This should be simple and I’m sure it is for you. I’m a Rails and jQuery newbie reading the Rails API for link_to and it suggests html_options = {} but there is no example I could find. Below is the html I want to end up because I want to use a jquery plugin for a modal dialog box for a contact form (if there is an easier Rails way, I’m happy to hear):
<a href="http://mywebsite.com/contact-us.html" name="box" class="close-reveal-modal" data-reveal-id="myModal">Get more info.</a>
Based on my reading of the api, this is my best guess but it fails:
<%= link_to 'Get more info', contact_us_path, :class => 'close-reveal-modal', html_options = {"data-reveal-id = 'myModal'"} %>
Yanking out the html_options section works, but without the call to the plugin. What I get are errors about missing closing parens, but that doesn’t make sense because everything is closed. Am I misunderstanding html_options?, sam
You actually don’t even need
html_optionsat all. Rails 3 supports adataoption that accepts a hash and turns that hash into individualdata-*attributes:The docs for that option are actually on the
ActionView::Helpers::TagHelper#tagmethod.