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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -