Ruby on Rails,将submit_tag传输到按钮

时间:2013-07-09 07:03:38

标签: ruby-on-rails button submit

我有以下结构:

<script type='text/javascript'>
    $('#check_all').on("click", function(){ $('input[type="checkbox"]').click(); });
</script> 
   <%= form_tag what_to_do_files_path, method: :get do %>
   <%= submit_tag "Delete selected", :commit =>"delete" %>
   <%= submit_tag "Pictures/Info/Raw Int", :commit =>"pictures" %>
   <button type="button" id="check_all">Check / Uncheck All </button>

   lalala
   <%end%>

您可能已经注意到“删除”和“图片/ ..”按钮与“Ceck / Un ..”不同。我需要看起来像“Ceck / Uncheck buttom” 我试过用

<%= button_tag(type: "submit", class: "btn btn-default", value:"my_button") do %>
    Update list <i class="icon-repeat"></i>
<% end %>

但是params [:commit]没有抓住它。
问题是什么?如何将submit_tag转移到按钮? 提前致谢

1 个答案:

答案 0 :(得分:0)

另请参阅Railscasts Episode 38 Multibutton forms

试试这个

# form

<%= form_tag what_to_do_files_path do %>
 ...
 ...
 ...
  <%= button_tag :class => "btn btn-warning", :name => 'delete' do %> Delete selected <% end %>
  <%= button_tag :class => "btn btn-primary", :name => 'pictures' do %> Pictures/Info/Raw Int <% end %>

<% end %>

你的行为看起来像这样:

# controller

def what_to_do_files
  if params[:delete]
    # Do stuff for delete
  elsif params[:pictures]
    # Do stuff for pictures
  else
    # other commit
  end
end