Question

I have database table store

model name models/store/store.rb

class Store::Store < ActiveRecord::Base
...
end

controller controllers/store/maintenance_controller.rb

class Store::MaintenanceController < ApplicationController

  def index
    @stores = Store.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @stores }
    end
  end

  def new
    @store = Store.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @store }
    end
  end

routes.rb

  namespace :store do
    root :to => "store#index"
    resources :store, :path => 'maintenance', controller: 'maintenance', :as => 'maintenance'
  end

rake routes |grep store

      store_root        /store(.:format)                                           store/store#index
  store_maintenance_index GET    /store/maintenance(.:format)                               store/maintenance#index
                        POST   /store/maintenance(.:format)                               store/maintenance#create
    new_store_maintenance GET    /store/maintenance/new(.:format)                           store/maintenance#new
   edit_store_maintenance GET    /store/maintenance/:id/edit(.:format)                      store/maintenance#edit
        store_maintenance GET    /store/maintenance/:id(.:format)                           store/maintenance#show
                        PUT    /store/maintenance/:id(.:format)                           store/maintenance#update
                        DELETE /store/maintenance/:id(.:format)                           store/maintenance#destroy

if i enter localhost:3000/store its work but if i enter localhost:3000/store/new im getting error undefined method 'stores_path' for on line <%= form_for(@store) do |f| %>

what is wrong here ? Thank you (i already have store controller thats why i have to rename controller for store table if i want to use scaffolding)

Was it helpful?

Solution

Your form looks for a POST to stores_path, but it's store_maintenance_index_path where your route goes for the create action. So there is no stores_path.

Your setup isn't right..

You don't have any routes resources for stores, only for maintenances..

So the real question is, what are you trying to CRUD? Is it maintenances or stores?

If you want to CRUD stores, edit your routes to:

namespace :store do
  resources :stores
end

If you really want to edit the pathname to maintenance, something like this:

namespace :store do
  resources :stores, path: 'maintenances', controller: 'stores', as: 'stores'
end

You don't want to CRUD stores in a maintenances controller, that's just not right...

OTHER TIPS

Can you try to move your models/store/store.rb to models/store.rb, then change the line to:

class Store < ActiveRecord::Base
...
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top