In any case I can either get the url_for options to work or the html
options to work, but no matter how I arrange () or {} I cannot get both
to work together. As far as I can determine, the api documents do not
explicitly show this case either.
But we were sooooo close. The actual code has to be this:
That code does not work either. It does not generate an error but now I
am back to having the id and class attributes set in the <a> tag, but
not the onclick.
If this is taking too much of your time, why don't just wrap your link
in a span or div then control the class from there? Just a thought.
And I can confirm this works in 2.3.2 too, as per Nicholas post
link_to "link here", new_object_path, :method => :post, :confirm =>
'Press OK', :class => "css_class", :id => "css_id"
Thank you to all who replied. I am on Rails 2.3.2 and yes, the code
above does work for me as well. I cannot gather from the API documents
that this should work however, which is why I never tried it.
I think what was confusing you was the difference between url_options
and html_options. They are not named in the most descriptive format,
but the source is much clearer. The only things that end up in
url_options are things that you can pass to url_for: so
neither :method nor :confirm belong there. You'd pass a hash in that
position if you were, for instance, using old-style routes
(passing :controller and :action explicitly).
All the stuff that ends up producing HTML bits ends up in the last
option.
The example that I think several of the previous posters were thinking
of (splitting the two arrays with {}) is typically encountered with
form_for; but note that form_for takes URL parameters with the :url
key.