I'm going through a few Rails 3 and 4 tutorial and come across something I would love some insights on:
What is the difference between the Model.new and Model.create in regards to the Create action. I thought you do use the create
method in the controller for saving eg. @post = Post.create(params[:post])
but it looks like I'm mistaken. Any insight is much appreciated.
Create action using Post.new
def new
@post = Post.new
end
def create
@post = Post.new(post_params)
@post.save
redirect_to post_path(@post)
end
def post_params
params.require(:post).permit(:title, :body)
end
Create action using Post.create
def new
@post = Post.new
end
def create
@post = Post.create(post_params)
@post.save
redirect_to post_path(@post)
end
def post_params
params.require(:post).permit(:title, :body)
end
I have two questions
- Is this to do with a Rails 4 change?
- Is it bad practice to use
@post = Post.create(post_params)
?