快速提问,我正在构建一个rails应用程序,它能够包含多个“功能”,其中一个是rsyslog,其他功能可能是任何其他软件。以下是当前构造:
控制器:
resources :features do
scope module: "features/rsyslog” do
resources :rsyslog_inputs
resources :rsyslog_outputs
resources :rsyslog_rules
end
end
路线:
class Features::RsyslogInputsController < ApplicationController;end
class Features::RsyslogOutputsController < ApplicationController;end
class Features::RsyslogRulesController < ApplicationController;end
(控制器代码在这里不起作用)
控制器代码:
features/
features/rsyslog_inputs_controller.rb
features/rsyslog_outputs_controller.rb
features/rsyslog_rules_controller.rb
我很好奇,因为有多个功能,我想保持每个功能控制器嵌套在特定于该功能的目录中..即(包含所有rsyslog控制器的rsyslog)而不是构建结构像这样:
Class Features::Rsyslog::RsyslogInputsController < ApplicationController; end
这如何转换为控制器代码类定义?这样做:
{{1}}
(注意上面添加了Rsyslog)
RubyMine在类定义中第二组“::”上的“预期行尾”变得很糟糕......但是,这些路线很有效..我在这里错过了什么?这只是我的IDE很奇怪吗?
答案 0 :(得分:0)
app/features/rsyslog/inputs_controller.rb
应该定义
class Features::Rsyslog::InputsController < ApplicationController
...
end
不
class Features::Rsyslog::RsyslogInputsController < ApplicationController
...
end
然后:
scope :features do
scope :rsyslog do
resources :inputs, controller: 'features/rsyslog/inputs'
resources :outputs, controller: 'features/rsyslog/outputs'
resources :rules, controller: 'features/rsyslog/rules'
end
end
哪个收益率:
inputs GET /features/rsyslog/inputs(.:format) features/rsyslog/inputs#index
POST /features/rsyslog/inputs(.:format) features/rsyslog/inputs#create
new_input GET /features/rsyslog/inputs/new(.:format) features/rsyslog/inputs#new
edit_input GET /features/rsyslog/inputs/:id/edit(.:format) features/rsyslog/inputs#edit
input GET /features/rsyslog/inputs/:id(.:format) features/rsyslog/inputs#show
PATCH /features/rsyslog/inputs/:id(.:format) features/rsyslog/inputs#update
PUT /features/rsyslog/inputs/:id(.:format) features/rsyslog/inputs#update
DELETE /features/rsyslog/inputs/:id(.:format) features/rsyslog/inputs#destroy
outputs GET /features/rsyslog/outputs(.:format) features/rsyslog/outputs#index
POST /features/rsyslog/outputs(.:format) features/rsyslog/outputs#create
new_output GET /features/rsyslog/outputs/new(.:format) features/rsyslog/outputs#new
edit_output GET /features/rsyslog/outputs/:id/edit(.:format) features/rsyslog/outputs#edit
output GET /features/rsyslog/outputs/:id(.:format) features/rsyslog/outputs#show
PATCH /features/rsyslog/outputs/:id(.:format) features/rsyslog/outputs#update
PUT /features/rsyslog/outputs/:id(.:format) features/rsyslog/outputs#update
DELETE /features/rsyslog/outputs/:id(.:format) features/rsyslog/outputs#destroy
rules GET /features/rsyslog/rules(.:format) features/rsyslog/rules#index
POST /features/rsyslog/rules(.:format) features/rsyslog/rules#create
new_rule GET /features/rsyslog/rules/new(.:format) features/rsyslog/rules#new
edit_rule GET /features/rsyslog/rules/:id/edit(.:format) features/rsyslog/rules#edit
rule GET /features/rsyslog/rules/:id(.:format) features/rsyslog/rules#show
PATCH /features/rsyslog/rules/:id(.:format) features/rsyslog/rules#update
PUT /features/rsyslog/rules/:id(.:format) features/rsyslog/rules#update
DELETE /features/rsyslog/rules/:id(.:format) features/rsyslog/rules#destroy