In Rails 3, it was possible to insert an attribute into params like so:
params[:post][:user_id] = current_user.id
I'm attempting to do something similar in Rails 4, but having no luck:
post_params[:user_id] = current_user.id
. . . .
private
def post_params
params.require(:post).permit(:user_id)
end
Rails is ignoring this insertion. It doesn't throw any errors, it just quietly fails.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…