0

I created a new action on the ClientsController called update_establishments. I have a form for Client which I want to call that action without generating a new view. The action will generate a new view.

 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| %> ... 

this throws an error ActionController::UrlGenerationError in Clients#add_establishments with the explanation No route matches {:action=>"update_establishments", :id=>"35", :controller=>"clients"}

I made no changes on the routes.rb

Do I need to create a view called clients/update_establishments to make this work?

1 Answer 1

1

I think you need to add new route to your routes.rb file, something like:

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

and update method 'patch' for your form:

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.