Strange issue encountered with Ember controllers

I am currently using Ember Cli version: 0.2.3

Exploring Ember for the first time and experimenting with a simple app.

This is what I have in my templates/about.hbs

<h1>About</h1>

<p>Adding something interesting here</p>

<button type="btn btn=primary"{{action 'clickMe'}}>Click me!</button>

and in my controllers/about_controller.js

Blogger.AboutController = Ember.Controller.extend({
  actions: {
    clickMe: function() {
      alert('Trying something new');
    }
  }
});

Upon clicking the button, I encountered an error and after checking the syntax, I'm unable to identify what's causing it. I need a fresh perspective on this.

Uncaught Error: Nothing handled the action 'clickMe'. 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.

Although I understand the message, I am unsure of how to resolve this issue at the moment.

Answer №1

It seems like Ember is having trouble finding your controller. You can troubleshoot this issue by using Ember Inspector. Make sure to follow ES6 conventions within your Ember CLI project. For more information on this, you can check out this link.

To resolve this issue, try creating an about controller using the following command in your command line:

ember generate controller about

After creating the controller, don't forget to add your action manually.

Answer №2

Do you prefer using Ember CLI or the Ember Starter Kit for your project?

If you opt for Ember CLI, be sure to create files such as - app/templates/about.hbs app/controllers/about.js and don't forget to add an entry in app/router.js [assuming you have already done that.] The entry in router.js should look like this:

Router.map(function() {
  this.route('about');
 });

Your template/about.hbs file should contain:

<h1>About</h1>

<p>Here lies some interesting content</p>

<button {{action 'clickMe'}}>Click me!</button>

And your controllers/about.js should be structured as follows:

import Ember from 'ember';
export default Ember.ObjectController.extend({
actions:{
       clickMe: function() {
      alert('Something exciting will happen here');
    }
  }
});

Once you have made all these changes, run the following command in your terminal - ember server (this should begin running your server)

If you follow this pattern, your code should work seamlessly. Remember, naming conventions play a crucial role in Ember development.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to define defaultProps for a nested object?

Within a react component, there is a nested object defined in the propTypes. This setup is functioning correctly. UserCard.propTypes = { name: PropTypes.string, customer: PropTypes.shape({ email: PropTypes.string, phoneNumber: PropTypes.string, ...

The Execution of a Function Fails When Passed to a Functional Component

My functional component accepts a function called addEvent, which expects an event parameter. The problem arises when I try to call this function from props within another functional component, as the function does not seem to execute: const onOk = () =&g ...

The countdown value in Javascript is not being reset when clearInterval is called

Currently, I am working on implementing a swiper slider with a countdown feature that resets its value every time a slide change occurs. The countdown should restart when the next slide is displayed automatically. However, I have encountered an issue where ...

What is the purpose of using async/await in Node.js when it is inherently asynchronous, and in JavaScript as well, vice versa?

Apologies for my lack of experience in Javascript and NodeJS. I'm a total beginner, so please excuse my silly questions. I've been trying to wrap my head around the concept but haven't found a clear explanation. Here's what's conf ...

Error: Node.js/Express unable to connect to static assets

I recently deployed my Express application to a production server and encountered an issue with serving static assets. All of my assets are located in the /public directory, and I am using the following code to call the static middleware: // config.root ...

Flashing bug in the outFunction of jquery hover()

My friends and I are working on a website for a class project, but we're running into a strange issue with the outFunction part of our hover function. Whenever the mouse hovers over an element, a grey square fades in using .fadeIn(), but then immediat ...

Using JQuery to enable the movement of divs on a screen through clicking and dragging, without the use of

Recently, I've been experimenting with a small project involving draggable divs. However, the code I've written doesn't seem to be functioning properly, causing JQuery to become unresponsive. Is there an alternative method that is simple an ...

Number each element in sequence

Looking to give sequential numbering to elements by iterating through them. For instance, if there are 6 input elements, the goal is to update their names correspondingly like "name=input1", "name=input2", and so on. This involves using a for loop to reas ...

Techniques for retrieving user inputs upon loading the HTML document and detecting changes using JavaScript

I am new to using JS to pass data to Python. I have managed to collect the values when the HTML is loaded, but I am facing an issue where the value does not change when it is updated. Here is the code snippet that I have been working with: <input type= ...

Having trouble using jQuery's .off() method to remove an event handler?

I'm facing an issue with my jQuery code where the .off('click') method doesn't seem to be working. I've tried removing the event binding from '.reveal-menu', but it's not working as expected. The initial animation wo ...

Exploring Bootstrap datatables to search through nested table data with Codeigniter

I have implemented a table using bootstrap datatables and successfully enabled search functionality within the table. However, I have also included nested tables within each row of the main table. These nested tables are supposed to be displayed when clic ...

Run javascript code after the page has transitioned

Struggling to create a dynamic phonegap app with jQuery Mobile, the issue arises when loading JavaScript on transition to a new page. The structure of my index page is as follows: <body> <div data-role="page" id="homePage"> <div data- ...

Exploring AngularJS: Utilizing limitTo and filter

I'm having some trouble with using angular's limitTo and filter together. I want to search for a value in the search box, then apply a limit to the number of results displayed by entering a number in the filter box and clicking apply filter. Howe ...

What steps should I take to build a TypeScript project (using tsdx) while excluding the source files from the final output?

My goal is to convert a typescript project into javascript, but I'm encountering an issue where the project's source files are ending up in the dist folder. I suspect it may be related to my configuration settings, as I have reviewed the document ...

The transform operation has no effect whatsoever

Just a quick intro, I created an animated clock using CSS and HTML for homework, but now I want to enhance it by adding JavaScript functionality. I tried to sync the clock hands with the current time using JS, but for some reason, the animation always star ...

Console log is not displaying the JSON output

I am currently working on implementing a notification button feature for inactive articles on my blog. I want to ensure that the admin does not have to reload the page to see any new submitted inactive articles. To achieve this, I am looking to use Ajax, a ...

Exploring the utilization of functions beyond module exports

Striving to clearly communicate my intentions, please feel free to ask if anything is unclear. Within a file named www, I am configuring my socket as follows: var server = http.createServer(app); var io = require('socket.io')(server); require(& ...

JS Difficulty with Applying Underline in Contenteditable

Recently, I encountered a glitch with document.execCommand that seems puzzling. Allow me to explain the situation at hand. $("#underline-btn").click(function() { document.execCommand("underline"); }); <script src="https://ajax.googleapis.com/ajax/l ...

Error 404 in Angular HTTP Request

I'm encountering a 404 error while attempting to send a post request, along with a 'possibly unhandled rejection' error. Given my limited experience with Angular, any advice would be greatly appreciated. I've gone through the documentat ...

Update a document by removing elements from an array where the objects are of a certain value

I am trying to remove specific tweet objects from the timeline list within the user model. The tweets I want to remove are those authored by a user with a matching id user._id. I attempted the following approach: router.get("/follow/:userId", is ...