I am using Rails 3 and found that if I add :remote => :true, there will be added to the tag the data-remote = true attribute. But I can't find a way to add custom data- attributes to the urlhelper. The followings won't work:
<%= link_to projects_path, :history => "new"%>
<%= link_to projects_path, :data-history => "new"%> #this throws an error
<%= link_to projects_path, :data_history => "new"%>
What I want to generate is: New Project
anyone?
What about:
<%= link_to 'New Project', new_project_path, 'data-history' => 'new' %>
( http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to )
This is an elegant solution:
<%= link_to "foo", foo_path, data: { foo: "bar" } %>
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