开发者

How do I send information with a form_for form?

I have two submit buttons both using the same create action in my controller. How can I send information with a form (without the user inputting it)?

Example:

Button 1: Creates a database entry with 1.

B开发者_如何学Cutton 2: Creates a database entry with 2.


You can use a hidden field like this:

<%= form_for @model do |f| %>
  <%= f.hidden_field :entry, 1 %>
  <%= f.submit 'Button 1' %>

<%= form_for @model do |f| %>
  <%= f.hidden_field :entry, 2 %>
  <%= f.submit 'Button 2' %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜