akhil
akhil

Reputation: 19

Ruby on rails redirect_to

what does it mean ? redirect_to "" and return

Upvotes: 1

Views: 1787

Answers (1)

Austin Lin
Austin Lin

Reputation: 2564

According to the rails API docs: the return portion stops execution of anything else. In other words if you had the below the text would never print because of the return statement.

def go_home
    redirect_to(:action => "home") and return
    puts "This will never print"
  end

In the next example and return is called only if monkeys.nil? is true.

 def do_something
    redirect_to(:action => "elsewhere") and return if monkeys.nil?
    render :action => "overthere" # won't be called if monkeys is nil
  end

from: http://api.rubyonrails.org/classes/ActionController/Base.html

Upvotes: 5

Related Questions