Created
April 7, 2017 05:40
-
-
Save iissnan/3ced9c12d9222b400c90a16c53ca0b4b to your computer and use it in GitHub Desktop.
#Rails - Insert attributes into Request Params
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PostsController < ApplicationController | |
def create | |
Post.create!(post_params) | |
end | |
private | |
def post_params | |
params.require(post).permit(:some_attrs).merge(user_id: current_user.id) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See: http://stackoverflow.com/questions/16530532/rails-4-insert-attribute-into-params