All threads / undefined method `service_path' when adding best_in_place
Ask A Question


You’re not receiving notifications from this thread.

undefined method `service_path' when adding best_in_place

Felix Pujols asked in Rails

I have an application that has customers and services. Customers has_many services and service belongs_to customer. In the customer show page, I can add or delete services. But I can not edit services, so I'm using best_in_place to do that. but is not working. It returns undefined method `service_path'. I will appreciate any help, I'm new in software.

here is the repository link if you want to check the whole app.

I restarted the server, but it keeps returning the same error.


   <% @customer.service.each do |service| %>
      <%= best_in_place service, :process  %>
   <% end %>


def show
    @customer = Customer.find params[:id]
    @service = @customer.service.order('created_at DESC').limit(4)

  def edit
    @customer = Customer.find params[:id]


  def edit
    @customer = Customer.find params[:id]

    @service =[:id])

  def update
    @service = Service.find(params[:id])

    respond_to do |format|
      if @service.update(service_params)
        format.html { redirect_to @service, notice: 'Service was successfully updated.' }
        format.json { render :show, status: :ok, location: @service }
        format.html { render :edit }
        format.json { render json: @service.errors, status: :unprocessable_entity }


resources :customers do
    resources :services

Based on your routes.rb, your path should be customer_service_path() as it's nested. Check in your cli/terminal rails routes to see all the routes available to you.

I don't know best_in_place, but I reckon you can change the path to "post/put" to.

Thank you, but still not working.

I did that:

<td><%= best_in_place customer_service_path(), :process %></td>

an it's giving me an error:

No route matches {:action=>"show", :controller=>"services", :id=>"2"}, missing required keys: [:customer_id]

The error says it all :)
missing required keys: [:customer_id] You need to add both your customer_id and in there too, otherwise does not know which customer or service object to update. Note: that this not specfic for the best_in_place plugin, but is general Rails stuff.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 68,099+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2022 GoRails, LLC. All rights reserved.