我对生成的视图路径有疑问。我的 routes.rb 如下所示
Project::Application.routes.draw do
resources :project_templates do
resources :awards
end
...
project_template.rb 像这样
class ProjectTemplate < ActiveRecord::Base
belongs_to :user
has_many :awards #...
attr_accessible :user_id #...
...
奖.rb 喜欢
class Award < ActiveRecord::Base
belongs_to :project_template
attr_accessible :tier #..
...
并且生成的视图链接是这样的:awards_path
这种方式应用程序不起作用,我需要全部替换为project_template_awards_path
我不知道为什么生成器在没有project_template
前缀的情况下这样做,但我要求你帮助我找到解决这个问题的方法。也许有一些生成器命令会将缺少的后缀添加到路径中?我必须对另一个班级做同样的事情,requirement.rb
并且对此也有看法,所以我希望有一些神奇的命令可以解决我的问题。
rake routes | grep awards
给出以下输出:
project_template_awards GET /project_templates/:project_template_id/awards(.:format) awards#index
POST /project_templates/:project_template_id/awards(.:format) awards#create
new_project_template_award GET /project_templates/:project_template_id/awards/new(.:format) awards#new
edit_project_template_award GET /project_templates/:project_template_id/awards/:id/edit(.:format) awards#edit
project_template_award GET /project_templates/:project_template_id/awards/:id(.:format) awards#show
PUT /project_templates/:project_template_id/awards/:id(.:format) awards#update
DELETE /project_templates/:project_template_id/awards/:id(.:format) awards#destroy