灰燼(0.2.5),導軌(4.2),灰燼CLI軌,設計,灰燼CLI簡單驗證設計灰燼CLI的Rails:創建用戶模型
行動創建在用戶模式 '用戶/新'控制器。目前,Ruby代碼在數據庫中創建用戶,但JavaScript響應仍然失敗。在使用用戶模型創建的Ember CLI和Rails中,我一直無法找到很多資源。這裏是我迄今使用的資源(https://adibsaad.com/blog/setting-up-ember-cli-with-a-rails-back-end-and-token-authentication-authorization)和(http://kbarrett.com/blog/2014/03/24/authentication-with-ember-rails.html)。
POST http://localhost:3000/users 422(無法處理的實體)
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代碼
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
讓我知道如果我需要提供其他任何東西。
Started POST "/users" for ::1 at 2015-05-25 09:36:54 -0700
Processing by UsersController#create as JSON
Parameters: {"user"=>{"email"=>"[email protected]", "name"=>"Arin", "gradePoints"=>217.665, "gradeUnits"=>63, "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}}
(0.2ms) BEGIN
User Exists (0.4ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = '[email protected]' LIMIT 1
(0.1ms) ROLLBACK
Completed 422 Unprocessable Entity in 118ms (Views: 0.9ms | ActiveRecord: 0.7ms)
從瀏覽器開發者工具(或從rails服務器日誌)發佈您的請求數據。也許它會幫助某種方式。 –
所以我意識到,422是你在驗證失敗時纔會得到的迴應。然而,我似乎無法訪問我的錯誤,以停止保存併發回錯誤處理樣式。我試過操縱JSON響應,但沒有運氣。 – arinh