Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

about.js Is not working anymore

I am doing the EmberJS course and am on Stage 3 and have come to the about.js part of it. The 'What is Dracula's real name' Alert box worked and it was fine but then then when I did the second part with the picture. It broke entirely and gave me this error when I clicked on either of the buttons:

Uncaught Error: Nothing handled the action 'showPicture'. If you did handle the action, this error can be caused by returning true from an action handler in a controller, causing the action to bubble.

Here is my about.js file:

Blogger.AboutController = Ember.Controller.extend({
  isPictureShowing: false,
  actions: {
    showRealName: function() {
      alert('Dracula is fictional, but was inspired by the 15th-century Romnian general and Wallachian Prince Vlad III the Impaler.');
    },
    showPicture: function() {
       this.set('isPictureShowing', true);
  }
});

Here is my index.html file:

<!DOCTYPE html>
<html>

<head>
  <title>Dracula's blog</title>

  <link rel="stylesheet" href="css/bootstrap.css">

  <script src="libs/jquery-1.11.1.js"></script>
  <script src="libs/handlebars-v1.3.0.js"></script>
  <script src="libs/ember.js"></script>
  <script src="libs/ember-handlebars-loader-0.0.1.js"></script>

  <script src="blogger.js"></script>
  <script src="router.js"></script>

  <script src="controllers/about.js"></script>
  <script src="controllers/contact.js"></script>


  <script>
    EmberHandlebarsLoader.loadTemplates(['posts', 'about', 'contact', 'phone', 'email', 'application']);
  </script>
</head>

<body>
</body>
</html>

And here is my about.hbs file: (I have not written down the whole about Dracula as it is too long for me to type)

<h1>About Dracula</h1>

<button class="btn btn-primary" {{action 'showRealName'}}>Click here to learn dracula's real name!</button>

{{#if isPictureShowing}}

<p><img src="http://upload.wikimedia.org/wikipedia/en/2/29/Count_von_Count_kneeling.png" alt="A photo of dracula"></p>
{{else}}
  <button class="btn btn-info" {{action 'showPicture'}}>Click here to see a picture</button>
{{/if}}

Thanks if anyone can help!

Max

1 Answer

Looks like you're missing a closing curly brace } for the showPicture function.

Nicholas Hebb is correct. You're missing a closing }. It should be this:

Blogger.AboutController = Ember.Controller.extend({
  isPictureShowing: false,
  actions: {
    showRealName: function() {
      alert('Dracula is fictional, but was inspired by the 15th-century Romnian general and Wallachian Prince Vlad III the Impaler.');
    },
    showPicture: function() {
       this.set('isPictureShowing', true);
    }
  }
});

If you ever want to do a quick check of your JS syntax, try using JSHint.

The buttons still don't work, they are just returning the same error.