0

这应该很简单,我相信它适合你。我是 Rails 和 jQuery 新手,正在阅读用于 link_to 的 Rails API,它建议 html_options = {} 但我找不到示例。下面是我想要结束的 html,因为我想将 jquery 插件用于联系表单的模式对话框(如果有更简单的 Rails 方式,我很高兴听到):

 <a href="http://mywebsite.com/contact-us.html" name="box" class="close-reveal-modal" data-reveal-id="myModal">Get more info.</a>

根据我对 api 的阅读,这是我最好的猜测,但它失败了:

 <%= link_to 'Get more info', contact_us_path, :class => 'close-reveal-modal', html_options = {"data-reveal-id = 'myModal'"} %>

抽出 html_options 部分有效,但没有调用插件。我得到的是关于缺少关闭括号的错误,但这没有意义,因为一切都已关闭。我误解了 html_options 吗?,山姆

4

2 回答 2

1

您必须在选项中使用 ruby​​ 哈希。ERB 代码可能如下所示

<%= link_to 'Get more info', contact_us_path, :class => 'close-reveal-modal', :data => { 'reveal-id' => 'myModal'} %>
于 2012-09-06T19:26:57.577 回答
1

你实际上根本不需要html_options。Rails 3 支持data接受散列并将散列转换为单独data-*属性的选项:

<%= link_to 'Get more info', contact_us_path, :class => 'close-reveal-modal', :data => { :reveal_id => 'myModal' } %>

该选项的文档实际上在ActionView::Helpers::TagHelper#tag方法上。

于 2012-09-06T19:27:12.773 回答