dimanche 24 mai 2015

Ember CLI Rails: Creating user model

Ember (0.2.5), Rails (4.2), Ember CLI Rails, Devise

Action for creating the user model on the 'user/new' controller. Currently the ruby code creates the user in the database however the javascript response is still failing. I haven't been able to find much resources on Ember CLI and Rails with user model creation. Here are the resources I have been using so far (http://ift.tt/1FJqw6E) and (http://ift.tt/QgwEgs).

POST http://localhost:3000/users 422 (Unprocessable Entity)

actions: {
createUser: function() {
  var user = this.store.createRecord('user', {
    name: this.get('name'),
    gradePoints: this.get('gradePoints'),
    gradeUnits: this.get('gradeUnits'),
    email: this.get('email'),
    password: this.get('password')
  });
  var self = this;
  user.save().then(function() {
    self.get('session').authenticate('ember-simple-auth-authenticator:devise', {
      identification: user.get('email'),
      password: user.get('password')
    }).then((function() {
      self.transitionToRoute('dashboard');
    }));
  }, function() {
    alert('Failed to register user.');
  });
 }
}

Ruby Code

class UsersController < ApplicationController
  respond_to :json

  def create
    user = User.new(user_params)

    binding.pry
    if user.save
      render json: user, status: :created
    else
      respond_with user
    end
  end

  private

  def user_params
    params.require(:user).permit(:name, :email, :gradePoints, :gradeUnits, :password, :password_confirmation)
  end

end

Let me know if I need to provide anything else.




Aucun commentaire:

Enregistrer un commentaire