I am beginner in Ruby on Rails and want to understand how come redirect_to an instance variable.
def create
@article = Article.new(params[:article])
@article.save
redirect_to @article
end
what does redirect_to @article imply?
It redirects (through Rails magic located in url_for
, if I remember correctly) to article's show
page.
It means
article /articles/:id article#show
It will redirect you to article's show action, check routes by executing rake routes
Notice the article GET /articles/:id articles#show - which gets matched when you do redirect_to(@article)
also read http://api.rubyonrails.org/classes/ActionController/Redirecting.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With