how do you get a link_to to generate something like
<a class="myclass".....
this is my code
<%= link_to "link", :controller => :my_controller, :action => :index, :class=>("on" if request.path =~ /\/my_controller/ ) %>
If you read the API, you'll see the following example:
link_to(body, url_options = {}, html_options = {})
This means the syntax for link_to is "link to something, then something else in braces, then another thing in braces." Another way of interpreting it is that the chunks have to be hashes.
link_to "link",
{ :controller => :my_controller, :action => :index },
{ :class=>("on" if request.path =~ /\/my_controller/ ) }
Which can all be placed on one line if you like.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With