form_for text_area

时间:2016-03-21 17:57:02

标签: ruby-on-rails

我在rails form helper中有一个text_area:

<%= form_for(@comment, remote: true) do |f| %>
  <%= f.text_area :content, placeholder: "Comment...", class: "common", 
id: "comments-@post.id"%>
  <span><%= hidden_field_tag :post_id, @post.id %></span>
  <%= f.submit "Post Comment", class: "comment-submit btn btn-primary" %>
<% end %>

我想在text_area的css id中添加一个ID号,这样一旦翻译就像id="comments-1"id="comments-42"

为了做到这一点,我需要使用一些嵌入式ruby,因为id号存储在变量@ post.id中,但我收到错误是因为我正在使用嵌入式ruby:({ {1}})更多嵌入式ruby:(@post.id

有办法解决这个问题吗?

1 个答案:

答案 0 :(得分:2)

id: "comments-@post.id"替换为id: "comments-#{@post.id}"

相关问题