Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8742647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:32:13+00:00 2026-06-13T11:32:13+00:00

I’m creating a router-based EmberJS app (strongly modelled on the excellent router guide ).

  • 0

I’m creating a router-based EmberJS app (strongly modelled on the excellent router guide). However, I’m quite muddled over what belongs in a view vs in a controller.

I totally get that {{action showFoo}} often indicates a state change and that the Router is the state machine for my app. But some of my actions don’t fall into that category.

Here’s an example from my actual code (html simplified but mustaches intact). I want to have a login form that works via ajax (i.e. the html form doesn’t post directly to the server, it tells my ember app to attempt a login via json).

<form>
    Email Name: {{view Ember.TextField valueBinding="email"}}
    Password:  {{view Ember.TextField valueBinding="password"}}
    <button type="submit" {{ action logIn target="this" }}>Sign in</button>  
</form> 

The valueBindings are fields in my loginController but the logIn handler is in my view (because I couldn’t figure out how to tell the template to call the controller). I feel like this is a weird distribution & I’m not sure what the right Ember approach is to this.

I don’t think the router should be handling the action because requesting a login attempt isn’t really a state change. The loginController feels like the right place to try the login. After a login response is received then that controller could trigger the state change.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:32:13+00:00Added an answer on June 13, 2026 at 11:32 am

    I don’t think the router should be handling the action because requesting a login attempt isn’t really a state change.

    I think that’s exactly the case: attempting a login should transition to an authenticating state, where for example another click to “login” is ignored.

    So IMHO this should be handled by the router. I’m thinking about something like this, see http://jsfiddle.net/pangratz666/97Uyh/:

    Handlebars:

    <script type="text/x-handlebars" >
        {{outlet}}
    </script>
    
    <script type="text/x-handlebars" data-template-name="login" >
        <p class="info">{{message}}</p>
        Login to view the admin area <br/>
        Email: {{view Ember.TextField valueBinding="email" }} <br/>
        Password: {{view Ember.TextField valueBinding="password" }} <br/>
        <button {{action login}} >Login</button>
    </script>
    
    <script type="text/x-handlebars" data-template-name="authenticating" >
        Communicating with server ...
    </script>
    
    <script type="text/x-handlebars" data-template-name="admin" >
        Hello admin!
    </script>
    

    ​

    JavaScript:

    App = Ember.Application.create();
    
    App.ApplicationController = Ember.Controller.extend({
        login: function() {
            // reset message
            this.set('message', null);
    
            // get data from login form
            var loginProps = this.getProperties('email', 'password');
    
            // simulate communication with server
            Ember.run.later(this, function() {
                if (loginProps.password === 'admin') {
                    this.set('isAuthenticated', true);
                    this.get('target').send('isAuthenticated');
                } else {
                    this.set('message', 'Invalid username or password');
                    this.set('isAuthenticated', false);
                    this.get('target').send('isNotAuthenticated');
                }
            }, 1000);
    
            // inform target that authentication is in progress        
            this.get('target').send('authenticationInProgress');
        },
        logout: function() {
            this.set('isAuthenticated', false);
        }
    });
    App.ApplicationView = Ember.View.extend({
        templateName: 'application'
    });
    
    App.LoginView = Ember.View.extend({
        templateName: 'login'
    });
    App.AdminView = Ember.View.extend({
        templateName: 'admin'
    });
    App.AuthenticatingView = Ember.View.extend({
        templateName: 'authenticating'
    });
    
    App.Router = Ember.Router.extend({
        root: Ember.Route.extend({
            index: Ember.Route.extend({
                route: '/',
                loggedOut: Ember.Route.extend({
                    route: '/',
                    connectOutlets: function(router) {
                        router.get('applicationController').connectOutlet('login');
                    },
                    login: function(router) {
                        router.get('applicationController').login();
                    },
                    authenticationInProgress: function(router) {
                        router.transitionTo('authenticating');
                    }
                }),
                authenticating: Ember.State.extend({
                    enter: function(router) {
                        router.get('applicationController').connectOutlet('authenticating');
                    },
                    isAuthenticated: function(router) {
                        router.transitionTo('loggedIn');
                    },
                    isNotAuthenticated: function(router) {
                        router.transitionTo('loggedOut');
                    }
                }),
                loggedIn: Ember.Route.extend({
                    route: '/admin',
                    connectOutlets: function(router) {
                        if (!router.get('applicationController.isAuthenticated')) {
                            router.transitionTo('loggedOut');
                        }
                        router.get('applicationController').connectOutlet('admin');
                    },
                    logout: function(router) {
                        router.get('applicationController').logout();
                    }
                })
            })
        })
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a small JavaScript validation script that validates inputs based on Regex. I
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I am writing an app with both english and french support. The app requests
I am using Paperclip to handle profile photo uploads in my app. They upload
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.