这是我未更改的控制器:
def create
@user = User.new(params[:user])
respond_to do |format|
if @user.save
format.html { redirect_to @user, notice: 'User was successfully created.' }
format.json { render json: @user, status: :created, location: @user }
else
format.html { render action: "new" }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
这是我的路线:
root :to => "songs#index"
match '/votes/:song_id/:user_id' => "votes#create"
resources :votes
resource :session
resources :users
resources :songs
match '/login' => "sessions#new", :as => "login"
match '/logout' => "sessions#destroy", :as => "logout"
和错误:
undefined method `user' for #<User:0x00000102b42a00>
Application Trace | Framework Trace | Full Trace
app/controllers/users_controller.rb:46:in `block in create'
app/controllers/users_controller.rb:45:in `create'
Request
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"oOzmpsbEJtnHC4YGeAf4N6pVxfK+Zf4W9ec+0E/Eds0=",
"user"=>{"email"=>"bhjjhb@hui.com",
"password"=>"[FILTERED]"},
"commit"=>"Create User"}
模型:
class User < ActiveRecord::Base
attr_accessible :email, :password
validates_uniqueness_of :user
validates_presence_of :password
has_many :votes
end