我在名为ClientsController
的{{1}}上创建了一个新操作。我有update_establishments
的表单,我想在不生成新视图的情况下调用该操作。该操作将生成一个新视图。
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| %> ...
这会引发错误Client
解释ActionController::UrlGenerationError in Clients#add_establishments
我对No route matches {:action=>"update_establishments", :id=>"35", :controller=>"clients"}
我是否需要创建名为routes.rb
的视图才能使其正常工作?
答案 0 :(得分:1)
我认为您需要为routes.rb
文件添加新路线,例如:
resources :clients do
member do
patch 'update_establishments'
end
end
并为您的表单更新方法'patch':
form_for @client, :url=>{:action=>'update_establishments'}, html: {method: "patch"} do |form|