WozPoz
WozPoz

Reputation: 992

Rails 3 - When loading a partial how to Combine a String (comment_) with a variable

I have the following:

commentable.id =3131

In the partial:

<%=f.text_area :content, :id=> 'comment_content_' commentable.id %>

I want it to make:

<textarea id="comment_content_3131" />

How do I combine the string with a variable in the partial? Thanks

Upvotes: 0

Views: 286

Answers (2)

Supy
Supy

Reputation: 390

As you would substitute any other string. :)

<%= f.text_area :content, :id=> "comment_content_#{commentable.id}" %>

Upvotes: 0

sosborn
sosborn

Reputation: 14694

Just concatenate the two strings:

<%=f.text_area :content, :id=> ('comment_content_' + commentable.id.to_s) %>

Upvotes: 2

Related Questions