strong parameters - Rails 4: Insert Attribute Into Params -
in rails 3, possible insert attribute params so:
params[:post][:user_id] = current_user.id
i'm attempting similar in rails 4, having no luck:
post_params[:user_id] = current_user.id . . . . private def post_params params.require(:post).permit(:user_id) end
rails ignoring insertion. doesn't throw errors, quietly fails.
found answer here. rather inserting attribute within controller action, can insert params definition merge. expand upon previous example:
private def post_params params.require(:post).permit(:some_attribute).merge(user_id: current_user.id) end
Comments
Post a Comment