views:

18

answers:

1

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

A: 

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 )

sled
Hey Sled, thanks for replying. I tried that, it gives me <a href="/projects/new" data-remote="true" history="new">New Project</a> see that the history="new", it's there but not with data- previx. do you know if there's a way to add data-prefix to it?
Nik
I've edited my answer, it should work now :) the error was, that you can't use "-" in symbols, you have to write it as literal.
sled
aha, got it! thanks. case closed
Nik