【问题标题】:Disable rails_best_practices RestrictAutoGeneratedRoutes for devise scope routes为设计范围路线禁用 rails_best_practices RestrictAutoGeneratedRoutes
【发布时间】:2021-05-29 10:29:08
【问题描述】:

为了限制设计自动生成的路线,我在我的路线文件中有这个...

  ## config/routes.rb  

  # Restrict auto generated devise routes
  devise_scope :user do
    resource :users,
             only: [:new, :create, :edit, :update],
             controller: 'users/registrations',
             path_names: { new: 'sign_up' },
             as: :user_registration
  end

控制器:

## app/controllers/users/registrations_controller

module Users
  # Copied by `devise` generator so we could override things.
  class RegistrationsController < Devise::RegistrationsController
    
    def new
     # some logic
    end

    def create
     # some logic
    end

    # # Overriding and call to `super` for these two method removes unused routes warning, I don't want this
    # # rubocop:disable Lint/UselessMethodDefinition
    # def edit
    #   super
    # end

    # def update
    #   super
    # end
    # # rubocop:enable Lint/UselessMethodDefinition

rails_best_practices linter 如果我不覆盖 RegistrationsController 中的 edit &amp; update 方法,则会发出警告 restrict auto-generated routes users (only: [:new, :create])

有没有办法为这些路由禁用RestrictAutoGeneratedRoutesCheck? 或者解决此警告的最可行方法是什么?谢谢。

【问题讨论】:

  • 我不明白你为什么会首先这样做,因为devise_for 可以让你自定义生成的路线,而无需重新发明轮子......
  • 我们可以使用 devise for 来限制路线吗?

标签: ruby-on-rails ruby devise


【解决方案1】:

如果自定义 rails_best_practices.yml 带有调整的 RestrictAutoGeneratedRoutesCheck 条目呢?见:https://github.com/flyerhzm/rails_best_practices

【讨论】:

  • 有没有办法禁用像robocop这样的特定块的检查?除了禁用对整个路由文件的检查之外,我没有找到任何东西。
【解决方案2】:

转到rails_best_practices.yml,您可以通过提供一个正则表达式或一个正则表达式数组来描述您不想成为的文件的路径,从而对任何规则应用ignored_files 选项:

在你的情况下RestrictAutoGeneratedRoutesCheck{ignored_files: 'routes.rb'}

【讨论】:

    猜你喜欢
    • 2018-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多