これが私の変更されていないコントローラーです:
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