用 grape 编写api/users/sign_up.json
代码
resource :users do
post "sign_up" do
# 不添加下面这句,会出现ActiveModel::ForbiddenAttributesError - ActiveModel::ForbiddenAttributesError:错误
# 添加了后出现TypeError - no implicit conversion of Symbol into String:错误
user_params = params.require(:user).permit(:email, :password, :password_confirmation)
@user = User.new(user_params)
if (params[:user][:password].length > 8) && (params[:user][:password] == params[:user][:password_confirmation]) && @user.save
{ :success => 1, :auth_token => @user.authentication_token, :email => @user.email }
else
{ :success => 0, :auth_token => "", :email => "" }
end
end
end
不添加下面这句,会出现 ActiveModel::ForbiddenAttributesError - ActiveModel::ForbiddenAttributesError:错误
添加了后出现 TypeError - no implicit conversion of Symbol into String:错误
user_params = params.require(:user).permit(:email, :password, :password_confirmation)
GG 过,解决不了!
这个错误怎么解决?