现在我有 2 个提交评论的表单。
表格类型 A
<%=form_for(([@community, @comment]), :remote => true, :class => 'form' ) do |f| %>
<%= f.text_field :body, :id => "body", :class => "chat" %>
<button type="submit" class="btn">submit</button>
<% end %>
表格类型 B
<%=form_for(([@user, @comment]), :remote => true, :class => 'form' ) do |f| %>
<%= f.text_field :body, :id => "body", :class => "chat" %>
<button type="submit" class="btn">submit</button>
<% end %>
现在,我想要一个link_to按钮,如果用户点击它,它的功能与那些表单一样。
当用户点击链接时,@comment
将自动填充,如下所示。
从表格类型 A
@comment = "this is for community"
从表格类型 B
@comment = "this is for user"
我怎样才能做到这一点?据我了解我的情况。
表单是put
类型,然后link_to是get
类型,所以不可能重用表单的事务。