views:

33

answers:

1

I'm diving into Ruby on Rails and I'm trying to get a grasp on the available docs for the API. I'm trying to find out what the list of "options" are for the redirect_to method in the ActionView API. In the RoR API docs, it says...

redirect_to(options = {}, response_status = {})

but it doesn't list what the available options are.

  1. What are the available options for the redirect_to method?
  2. Just so I don't have to ask more questions, where can I find this list of options in the API docs?

Thanks so much in advance for your help!

A: 

As the doc says:

Redirects the browser to the target specified in options. This parameter can take one of three forms: Hash, Record, String starting with protocol:// (like http://), String not containing a protocol, :back.

Example:

redirect_to :action => "your_action_name"  

or

redirect_to post_url(@post), :status => :found

UPDATE 1: (after the downvote ;) )

Its not about specific keyworks, its its "types" of data passed in the option. As you said, what about "id" or "action", they are a part of a hash. see 1.

  1. Hash - redirect_to :action => "show", :id => 5

  2. Record - post

  3. String starting with protocol - "http://google.com"

  4. String not containing a protocol - /images/foo.jpg

  5. :back

So, these are the 5 "types" of values which can be passed in redirect_to, it was again a copy from ruby docs because that is what is stands for. I cannot be more clear than that.

UPDATE 2

Let's take an example: Say, you have ordered an item and after you make the payment, you should be redirected back to that item's page which you have just ordered.

Code_for_placing_the_order

redirect_to :action => "show_item", :id => 5, :current_user => "john"

So, when you do this, the action, "show_item" will be called, which takes in id as an lookup value for the item and the current logged in user current_user.

So, as on a form submit, you call an action and pass the form values, you do the same in redirect.

UPDATE 3

The example I gave was of a hash. So, a hash is created which is passed over the URL to the redirected page.

key          | value
-------------------------
action       | show_item
id           | 5
current_user | john

Now, this hash is forwarded to the next page. The values of action and id should be same and then you can add ANY symbol you want to. They will just be forwarded with it's respective value where you can read them in your show_item action method.

PS: I am learning rails, suggestions are welcomed :)

zengr
ummm...what about 'id' which is an available option? what about 'action'? what about the others and what are they? i appreciate your help, but simply reposting the documentation that's confusing me doesn't help ;)
BeachRunnerJoe
why the downvote?
zengr
downvote wasn't mine, but the upvote is. thanks zengr, for clarifying that. can you help me better understand the names of the symbols that are being used in the options list (i.e. id, action, etc.)? are they arbitrarily named? if not, how do i know which symbols to use? thanks again
BeachRunnerJoe
updated and thanks. I repeat, I would love to get some expert comments on this question too. I wrote what I understand. :)
zengr
thanks. so when you want to specify a user's name, how did you know to use the symbol 'current_user'? Why not 'cur_user'? I'm trying to understand which symbols are supported and where the documentation is that defines their meaning.
BeachRunnerJoe
updated........
zengr
cool, thank you!
BeachRunnerJoe