【发布时间】:2010-09-23 14:40:10
【问题描述】:
我有一个用于基本用户身份验证和授权的 Rails 3 引擎 gem。在该 Gem 中,config/routes.rb 定义了以下内容
resources :users
match '/:controller(/:action(/:id))'
当我从需要此 gem 的应用程序中执行 rake routes 时,我得到以下路线
rake routes|grep users
users GET /users(.:format) {:controller=>"users", :action=>"index"}
users POST /users(.:format) {:controller=>"users", :action=>"create"}
new_user GET /users/new(.:format) {:controller=>"users", :action=>"new"}
edit_user GET /users/:id/edit(.:format) {:controller=>"users", :action=>"edit"}
user GET /users/:id(.:format) {:controller=>"users", :action=>"show"}
user PUT /users/:id(.:format) {:controller=>"users", :action=>"update"}
user DELETE /users/:id(.:format) {:controller=>"users", :action=>"destroy"}
这是我所期望的。
但是,当我尝试通过浏览器访问以下路线时
/users/137
/users/137/edit
我在日志中收到以下错误
AbstractController::ActionNotFound (The action '137' could not be found for UsersController):
actionpack (3.0.0) lib/abstract_controller/base.rb:114:in `process'
actionpack (3.0.0) lib/abstract_controller/rendering.rb:40:in `process'
...
有趣的是以下路径确实有效
/users/show/137
/users/edit/137
此外,如果我将以下内容添加到需要 gem 的应用程序中的 routes.rb 文件中,则一切都会按预期工作。
resources :users
是我遗漏了什么还是这是一个错误?
请注意,当我启动我的应用程序时,我也在执行以下操作 在我启动 rails 时的命令行上,我设置了以下环境变量
RAILS_RELATIVE_URL_ROOT="/my_app"
在 config.ru 中
map '/my_app' do
run MSEL::Application
end
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 routes