2014-08-27 47 views
0

我在ClientsController上創建了一個名爲update_establishments的新操作。我有一個Client的表格,我想在不生成新視圖的情況下調用該操作。該行動將產生新的觀點。RoR - 在窗體上不顯示視圖的情況下調用新操作

 
clients_controller.rb 
    def update_establishments 
     create_zip 
     respond_to do |format| 
     if @client.update(client_params) 
     set_zip 
     format.html { redirect_to @client, notice:'Estabelecimento adicionado com sucesso.'} 
     format.json {head :no_content} 
     else 
     format.html { render action: 'edit'} 
     format.json { render json: @client.error, status: :unprocessable_entity } 
     end 
    end 
    end  


clients/_locations_form.html.erb 

    form_for @client, :url=>{:action=>'update_establishments'} do |form| %> 
    ... 

,這將引發與解釋No route matches {:action=>"update_establishments", :id=>"35", :controller=>"clients"}

錯誤ActionController::UrlGenerationError in Clients#add_establishments 我在routes.rb

不需要做任何改變,我需要創建一個視圖名爲clients/update_establishments,使這項工作?

回答

1

我認爲你需要新的路由添加到您的routes.rb文件,是這樣的:你的形式

resources :clients do 
    member do 
    patch 'update_establishments' 
    end 
end 

和更新方法 '補丁':

form_for @client, :url=>{:action=>'update_establishments'}, html: {method: "patch"} do |form|

相關問題