在link_to rails 4中使用`data-toggle`和`data-target`的语法

时间:2015-02-27 08:27:55

标签: ruby-on-rails ruby-on-rails-4

我有:

<%= link_to :action=>'view_score_card',:id=>innings1_batting_datail.id,remote: true,:class=>"body_inner_icon" do %>

在此链接中,我想使用data-toggle="modal"data-target="#myModal1"。请告诉我正确的语法。

1 个答案:

答案 0 :(得分:2)

这些是link_to签名:

link_to(body, url, html_options = {})
link_to(body, url_options = {}, html_options = {})
link_to(options = {}, html_options = {})
link_to(url, html_options = {})

您希望它们最终出现在html_options块中。尝试:

<%= link_to 'link', {:action => 'view_score_card', :id => innings1_batting_datail.id}, {:remote => true, :class => "body_inner_icon", 'data-target' => "#myModal1", 'data-toggle' => "modal"} do %>

或者:

<%= link_to 'link', view_score_card_path(innings1_batting_datail), {:remote => true, :class => "body_inner_icon", 'data-target' => "#myModal1", 'data-toggle' => "modal"} do %>