我正在使用 Rails 最佳实践来验证我自己的代码。
./app/controllers/news_items_controller.rb:2 - remove unused methods (NewsItemsController#new)
./app/controllers/news_items_controller.rb:2 - remove unused methods (NewsItemsController#create)
./app/controllers/news_items_controller.rb:2 - remove unused methods (NewsItemsController#edit)
./app/controllers/news_items_controller.rb:2 - remove unused methods (NewsItemsController#update)
./app/controllers/news_items_controller.rb:2 - remove unused methods (NewsItemsController#destroy)
./app/controllers/pages_controller.rb:1 - remove unused methods (PagesController#new)
./app/controllers/pages_controller.rb:1 - remove unused methods (PagesController#create)
./app/controllers/pages_controller.rb:1 - remove unused methods (PagesController#edit)
./app/controllers/pages_controller.rb:1 - remove unused methods (PagesController#update)
./app/controllers/pages_controller.rb:1 - remove unused methods (PagesController#destroy)
./app/controllers/registrations_controller.rb:2 - remove unused methods (RegistrationsController#update)
./app/controllers/registrations_controller.rb:8 - remove unused methods (RegistrationsController#after_sign_up_path_for)
./app/controllers/registrations_controller.rb:1 - remove unused methods (RegistrationsController#new)
./app/controllers/registrations_controller.rb:1 - remove unused methods (RegistrationsController#create)
./app/controllers/registrations_controller.rb:1 - remove unused methods (RegistrationsController#edit)
./app/controllers/registrations_controller.rb:1 - remove unused methods (RegistrationsController#destroy)
./app/controllers/static_controller.rb:2 - remove unused methods (StaticController#new)
./app/controllers/static_controller.rb:2 - remove unused methods (StaticController#create)
./app/controllers/static_controller.rb:2 - remove unused methods (StaticController#edit)
./app/controllers/static_controller.rb:2 - remove unused methods (StaticController#update)
./app/controllers/static_controller.rb:2 - remove unused methods (StaticController#destroy)
这里的动作大多是未使用的方法。唯一的问题是这些动作甚至没有定义......我尝试使用remove_method
但没有成功。
例如, news_items_controller 只有index
andshow
而路由只定义index
and show
。
我的班级定义如下:NewsItemsController << StaticController << ApplicationController << ActionController::Base
我的猜测是 ActionController::Base 正在定义它们,有趣的是它没有显示“ApplicationController”......
这是StaticController的内容
# encoding: utf-8
class StaticController < ApplicationController
end
并且没有路线指向StaticController
。
还有routes.rb
ActiveAdmin.routes(self)
scope "(:locale)", :locale => /ru|en/ do
devise_for :users, :controllers => { :registrations => "registrations" }
resources :news_items, only: [:show, :index]
resources :pages, :only => [:show]
root to: "home#index"
end
root to: "home#index"