我正在使用has_one
关系并收到错误消息。 create
方法未使用create
来查找参数。
错误日志:
NoMethodError (undefined method `create' for #<Verification:0x007fcb71e2bd98>):
app/controllers/verifications_controller.rb:7:in `create'
verificationsController:
def create
@user = User.find(params[:user_id])
@verification = current_user.verification.create(verification_params)
end
private
def verification_params
params.require(:verification).permit(:user_id, :paypal_firstname, :paypal_lastname, :paypal_email, :paypal_verified)
end
路线:
devise_for :users ,
:path => '' ,
:path_names => {:sign_in => 'login', :sign_out => 'logout', :edit => 'profile'},
:controllers => {:omniauth_callbacks => 'omniauth_callbacks',
:registrations => 'registrations', :verifications => 'verifications'
}
resources :users, only: [:index, :show] do
end
resources :users do
resources :verifications, only: [:create]
end
get '/users/:id/paypal_verification' => 'users#paypal_verification'
patch '/users/:id/paypal_verification' => 'users#paypal_verification'
usersController:
def paypal_verification
# @verification = @user.verification.new
@user = current_user
@verification = Verification.create(params[:verification])
@user.verification = @verification
end
答案 0 :(得分:1)
尝试current_user.create_verification(verification_params)
。