我有命名空间控制器实体::客户
class Entities::CustomersController < ApplicationController
...
end
和命名空间的 ActiveRecord 模型:
class Entities::Customer < Entities::User
end
在我的 routes.rb 文件中,我有:
resources :customers, module: :entities
模块 :entities 在那里,因为我不想有如下路线:
/entities/customers但仅限:
/客户。
当我呈现我的表单时,问题就开始了:
<%= simple_form_for(@customer) do |f| %>
<%= f.input :email %>
<%= f.input :password %>
<%= f.input :name %>
<%= f.button :submit %>
<% end %>
这会引发错误:类的未定义方法“entities_customer_path”..
所以错误是rails认为正确的路径是带有前缀实体的。
耙路线给我:
Prefix Verb URI Pattern Controller#Action
customers GET /customers(.:format) entities/customers#index
POST /customers(.:format) entities/customers#create
new_customer GET /customers/new(.:format) entities/customers#new
edit_customer GET /customers/:id/edit(.:format) entities/customers#edit
customer GET /customers/:id(.:format) entities/customers#show
PATCH /customers/:id(.:format) entities/customers#update
PUT /customers/:id(.:format) entities/customers#update
DELETE /customers/:id(.:format) entities/customers#destroy