0

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)

Muflix
  • 6,192
  • 17
  • 77
  • 153

2 Answers2

0

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

class Store < ActiveRecord::Base
...
end
Victor
  • 13,010
  • 18
  • 83
  • 146
0

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

Tim Baas
  • 6,035
  • 5
  • 45
  • 72
  • i want CRUD store table but crud actions have in maintance controller because im using store controller for anything else it is possible ?? – Muflix Sep 22 '13 at 15:05
  • ok i will think about it maybe i will rename store controller – Muflix Sep 22 '13 at 15:06
  • 1
    If you really want this, you could have a `StoreController`, and a `StoresController`, single and plural. But my advise would be one controller per model. Also if it's only the pathnames you're worried about, than just use a `scope` for `/store`. And find out more information about routing in general.. – Tim Baas Sep 22 '13 at 15:31