目前我的情况是将一个按钮添加到索引表单中。这与搜索和复选框等其他功能组合完美配合,这些功能也是索引表单的一部分。
index.html.erb
的代码:
<%= form_tag order_path, :method => 'get' do %>
<p>
<%= submit_tag "Historical Search", :account_short => nil %>
<%= text_field_tag :search, params[:search] %>
</p>
<% end %>
<%= form_tag sendnext_order_path, :method => :put do %>
<%= submit_tag "Send to Desk" %><br/>
-- other code from index-form
<% end %>
结合controller
:
def sendnext
Order.update_all(["status_id = ? ", "2"], :id => params[:order_ids])
redirect_to order_path, notice: 'Order succesfully send to desk.'
end
现在我想在Send to Desk
按钮旁边添加第二个按钮,而不是使用其他动作。到现在为止,我无法实现这一点。
请指教。欢迎任何反馈。
答案 0 :(得分:0)
<%= button_to('Send to Desk', 'sendnext', :method => "put") %>
<%= button_to('Cancel Order', 'cancelorder ', :method => "put") %>
将为您处理表格。 submit_tag
正在提交我认为的第一个表单。
例如
<%= button_to "New", :action => "new" %>
将生成
# => "<form method="post" action="/controller/new" class="button_to">
# <div><input value="New" type="submit" /></div>
# </form>"
答案 1 :(得分:0)
感谢您的帮助。我找到了一个可以实现当前要求的工作解决方案:
index.html.erb
如下所示:
<%= form_tag updateorder_order_path, :method => :put do %>
<%= submit_tag "To Desk" %><br/>
<%= submit_tag "Cancel Order" %>
-- other code like data fields
<%end %>
controller.rb
如下所示:
def updateorder
if params[:commit] == "To Desk"
Order.update_all(["status_id = ? ", "2"], :id => params[:order_ids])
redirect_to order_path, notice: 'Order(s) successfully send to desk.'
elsif params[:commit] == "Cancel Order"
Order.update_all(["status_id = ? ", "3"], :id => params[:order_ids])
redirect_to order_path, notice: 'Order(s) successfully cancelled.'
else
Order.update_all(["status_id = ? ", "5"], :id => params[:order_ids])
redirect_to order_path, notice: 'Order(s) successfully updated.'
end
end
routes.rb
包含下一个代码:
resources :orders do
put 'updateorder', :on => :collection
end