1

我有以下表格

<%= form_tag url_for(:action => "clients_new") do %>
    <%= text_field_tag 'some_text' %>
    <%= text_field_tag 'soem_text' %>
    <%= submit_tag 'Search' %>
    <%= submit_tag 'Download xls' %>
<% end %>

我需要为两者形成相同的动作,search并且download以相同的形式我该怎么做。

我的控制器是

class ClientsController < ApplicationController
  respond_to :html, :xls

def clients_new
  blahblah
  if params[:clien]=='download'
  respond_to do |format|
   format.xls
  end
else
  respond_to do |format|
   format.html
  end
end
end
end
4

2 回答 2

0

There is no such thing as 2 submit buttons in the same form. The submit action would only go to one method con your controller.
What you can do, is have maybe a radio element to choose between search and download, then you check which option is active on your controller before do stuff.

于 2013-08-30T12:08:45.450 回答
0
<%= form_tag url_for(:action => "clients_new") do %>
    <%= text_field_tag 'some_text' %>
    <%= text_field_tag 'soem_text' %>
<%if @form_type == 'search'%>
<%=hidden_tag :form_type, "search"%>
    <%= submit_tag 'Search' %>
<%else%>
    <%= submit_tag 'Download xls' %>
<%=hidden_tag :form_type, "download"%>
<%end%>
<% end %>

Then in controller

  def clients_new
      if params[:form_type] == "search"
    #do something
    else
    end
end
于 2013-08-30T12:10:36.247 回答