Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ruby on rails redirect_to with instance variable [duplicate]

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?

like image 838
user3726986 Avatar asked Jul 16 '14 09:07

user3726986


2 Answers

It redirects (through Rails magic located in url_for, if I remember correctly) to article's show page.

like image 87
Marek Lipka Avatar answered Sep 18 '22 19:09

Marek Lipka


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

like image 36
Deepti Kakade Avatar answered Sep 21 '22 19:09

Deepti Kakade