Mounted engine on a ruby on rails application sends NoMethodError message when trying to edit a record from the host application

Viewed 20

I am using a mounted engine on an application with Rails 5.2.8.1

Rails.application.routes.draw do

  mount MyEngine::Engine, at: "/countries", as: 'country_table'
  
end

Here are the routes for the engine

MyEngine::Engine.routes.draw do
  scope module: 'table' do
    post '/', action: 'index'
    get '/:id/edit', action: 'edit'
    post '/:id/update', action: 'edit'
  end
end

In the host application I have a Country model which I am trying to edit. I have a few seeds in my DB.

7.times do |i|
    country = Country.new
    country.name = "Country#{i}"
    country.save
end

Here is my controler

module MyEngine
  class TableController < ApplicationController

    def edit
      # Identify the resource
      @country = Country.find(params[:id])
    
      # render the form
      render :edit
    end

This is my edit.html.erb view

<%= form_with model: @country do |form| %>
  <%= form.text_field :name %>
  <%= form.submit %>
<% end  %>

When I hit http://localhost:3000/countries/3/edit I get this error

NoMethodError in MyEngine::Table#edit

undefined method `country_path' for #<#<Class:0x000055aa7e4cbc50>:0x000055aa7e5478a0>
Did you mean?  country_table

If someone knows what is wrong here, I will listen carefully...

0 Answers
Related