0

我有数据库表store

型号名称models/store/store.rb

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

控制器控制器/商店/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

路线.rb

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

rake 路线 |grep 商店

      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

如果我输入 localhost:3000/store 它的工作但是如果我输入 localhost:3000/store/new 我 undefined method 'stores_path' for 在线上 遇到错误<%= form_for(@store) do |f| %>

这里有什么问题?谢谢(我已经有了存储控制器,所以如果我想使用脚手架,我必须为存储表重命名控制器)

4

2 回答 2

0

您的表单寻找POSTto stores_path,但它是store_maintenance_index_path您的路线去创建操作的地方。所以没有stores_path

你的设置不对。。

您没有任何路线资源stores,只有maintenances..

所以真正的问题是,你想 CRUD 做什么?是maintenances还是stores

如果您想 CRUD stores,请将您的路线编辑为:

namespace :store do
  resources :stores
end

如果你真的想编辑维护的路径名,像这样:

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

您不想storesmaintenances控制器中进行 CRUD,这是不对的……

于 2013-09-22T15:00:45.763 回答
0

您可以尝试将您的移动models/store/store.rbmodels/store.rb,然后将行更改为:

class Store < ActiveRecord::Base
...
end
于 2013-09-22T14:48:45.580 回答