Rails Best Practices误报未使用的方法

时间:2013-01-15 12:48:25

标签: ruby-on-rails ruby false-positive rbp

我使用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只有indexshow,而路由只定义indexshow

我的课程定义如下:NewsItemsController << StaticController << ApplicationController << ActionController::Base

我的猜测是ActionController :: Base正在定义它们,有趣的是它没有显示&#34; ApplicationController&#34; ...

这是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"

1 个答案:

答案 0 :(得分:2)

Rail最佳实践经常沉迷于显示误报。 在这种情况下,我不会对RBP太过信任,而是继续将所有操作排除在rails_best_practises.yml文件中。

例如:

RemoveUnusedMethodsInControllersCheck: { except_methods: ['YourController#search'] }