0

目前我有一个按钮被添加到索引表单的情况。这与搜索和复选框等其他功能完美结合,这些功能也是索引表单的一部分。

的代码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按钮具有与现有工作按钮不同的另一个操作。直到现在我还没有能力意识到这一点。

请指教。欢迎任何反馈。

4

2 回答 2

0

使用button_to

<%= 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>"
于 2012-11-29T17:42:46.640 回答
0

谢谢你的帮助。我找到了一个可行的解决方案,可以实现我当前的要求:

The index.html.erb looks like the following:

<%= form_tag updateorder_order_path, :method => :put do %> 
   <%= submit_tag "To Desk" %><br/> 
   <%= submit_tag "Cancel Order" %> 

   -- other code like data fields

 <%end %>

The controller.rb looks like the following:

  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  

The routes.rb contains the next code:

     resources :orders do
        put 'updateorder', :on => :collection
     end
于 2012-11-30T09:51:09.320 回答