attaching a css class to a link_to method

Hi Sean,

I think the code you're after is:

<%= link_to "Downloads", {:controller => 'downloads'}, {:class => "here"} -%>

Here's my take on the API's spec, but I'm fairly new to Ruby / Rails, so I might be wrong:

link_to takes a name argument. In the example above, this is "Downloads".

It also takes a hash of options. If no options are specified, it defaults to the empty hash, denoted by {}. In the example above, options is the hash: {:controller => 'downloads'}

It also takes a second hash of html_options, which defaults to nil, if no hash is supplied. In the example above, html_options is {:class => "here"}

A source of confusion is that if a hash is the last argument to a Ruby method, the brackets may be omitted. Therefore the following is equivalent to the example above:

<%= link_to "Downloads", {:controller => 'downloads'}, :class => "here" -%>

Finally, the following is *not* equivalent to the first example, and will result in options containing both controller and class entries; meanwhile html_options will be nil:

<%= link_to "Downloads", :controller => 'downloads', :class => "here" - %>

Hope this helps some.

Cheers, Louis.

The snippet from the API that you're looking at is the method signature. So to answer your question, yes this part of the API only specifies the order of the arguments (and their names, but that's not too important to you.) To get a complete picture of what a method does, consider also the description of the method.

For the link_to method, that description includes the following text: "The html_options will accept a hash of html attributes for the link tag. It also accepts 3 modifiers that specialize the link behavior.

    * :confirm => 'question?': This will add a JavaScript confirm prompt with the question specified. If the user accepts, the link is processed normally, otherwise no action is taken.     * :popup => true || array of window options: This will force the link to open in a popup window. By passing true, a default browser window will be opened with the URL. You can also specify an array of options that are passed-thru to JavaScripts method.     * :method => symbol of HTTP verb: This modifier will dynamically create an HTML form and immediately submit the form for processing using the HTTP verb specified."

This explains precisely what are considered valid contents for the html_options hash (i.e. the third argument to link_to).

For reference, a complete description of the link_to method, check out:

Hope this helps.

Cheers, Louis.