2012-09-06 15 views
0

这应该很简单,我相信它适合您。我是Rails和jQuery新手,正在阅读link_to的Rails API,它建议使用html_options = {},但没有我能找到的示例。下面是我要结束了,因为我想用一个jQuery插件用于接触形式的模态对话框(如果有一个更简单的Rails的方式,我很高兴听到)的HTML:在link_to中传递字符串

<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?,sam

+0

您的'html_options'哈希有点有趣。试试'{'data-reveal-id'=>'myModal'}'而不是? –

回答

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 method

1

你必须在选项中使用红宝石散列。 ERB代码可能看起来像这样

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

我是如何在Rails API中错过的?我仍然无法找到:数据记录在案?谢谢。 – sam452