Reputation: 813
I'm using rails 4.
Is there any way to add post.id to link_to href?
<%= link_to_modal "Demo Form", "#demo-form-"+post.id, :class=>"button" %>
and
<%= link_to_modal "Demo Form", "#demo-form-"(post.id), :class=>"button" %>
Doesn't work.
Upvotes: 0
Views: 122
Reputation: 38645
Adding this answer to point out the error and how you could have fixed it with your existing code.
The only problem with this line:
<%= link_to_modal "Demo Form", "#demo-form-"+post.id, :class=>"button" %>
is that you're trying to concat a Fixnum
with string
which should have generated can't convert Fixnum into String
error.
You could have used post.id.to_s
to fix what you already had as:
<%= link_to_modal "Demo Form", "#demo-form-" + post.id.to_s, :class=>"button" %>
And your second line:
<%= link_to_modal "Demo Form", "#demo-form-"(post.id), :class=>"button" %>
is invalid and should have thrown a SyntaxError
.
I'm unsure on your choice of syntax, but I like @Surya's answer better that uses the string interpolation.
Upvotes: 1
Reputation: 16022
Try this:
<%= link_to_modal "Demo Form", "#demo-form-#{post.id}", :class=>"button" %>
Upvotes: 2