A newbie question regarding the ActiveRecord‘s save method.
If i have this code (as in rails guide):
def create
@post = Post.new(params[:post])
if @post.save
redirect_to @post
else
.....
end
end
The save method returns the new created Post object? How, after the code @post.save, rails know how to substitute the redirect_to @post with the proper post_id (1 or 2 or 3 or ….) to build the link?
I’m going to explain it by presenting another piece of code that should make things easy to understand
Now
:usercontains the following information based on the User model: id, name, email, telephone.So that means we have actually assigned to
@userthe above hashes.The
redirect_towill retrieve the hashes that is already stored in@userand display the new profile page.I hope it helped.