请我尝试运行此代码,但我确实在UsersController中创建了ActiveModel :: ForbiddenAttributesError #create error,我该如何解决呢
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
#debuger
end
def agent_signup
@user = User.new
end
def create
@user = User.new(params[:user]) # Not the final implementation!
if @user.save
# Handle a successful save.
else
render 'agent_signup'
end
end
private
def user_params
params.require(:user).permit(:name, :email, #:password,
#:password_confirmation
)
end
end
答案 0 :(得分:1)
应该是
# Wrong
@user = User.new(params[:user]) # Not the final implementation!
# Correct
@user = User.new(user_params) # Not the final implementation!
为了使用允许的参数
答案 1 :(得分:0)
试试这个解决方案。你需要允许参数。
def create
@user = User.new(user_params)
if @user.save
# Handle a successful save.
else
render 'agent_signup'
end
end