【问题标题】:rails-4 autocomplete and devise authorizationrails-4 自动完成和设计授权
【发布时间】:2017-03-25 10:11:30
【问题描述】:

我对 gem rails4-autocomplete 有疑问。这工作得很好,但是因为我已经为用户安装了 Devise,所以我需要连接才能使用自动完成,否则它不起作用。

确实,如果我撤回“Before_action: authenticate_user!”在 application_controller.rb 中,它可以工作,但我无法删除它。

如何跳过 rails4-autocomplete 上的身份验证,就像跳过类似的方法一样 认证索引和显示

Skip_before_action: authenticate_user !, only: [: index,: show]

我该怎么做?

【问题讨论】:

    标签: ruby-on-rails ruby autocomplete rubygems


    【解决方案1】:

    你现在可能已经想通了,但是你的问题的秘诀是运行

    rake routes
    

    您会注意到为您的自动完成创建了一个命名路由。然后,您只需将该方法名称列入白名单(您将从路由表中收集)

    所以看看路线,前面有“自动完成”的那条就是你需要的。

    然后在处理您的自动完成功能的控制器中添加一个白名单以供设计,如果它在该操作上,如下所示:

    skip_before_action :authenticate_user!, only [:index, :autocomplete_brand_website]
    

    我整理了一个示例应用程序,以最简单的形式说明了它是如何工作的:

    https://bitbucket.org/bunglify/so-autocomplete-devise/overview

    【讨论】:

      【解决方案2】:

      您可以使用 except 参数跳过某些操作的 before_action:

      before_action :authenticate_user!, except: [:index, :show]
      

      您也可以跳过在 UsersController 中使用 skip_before_action 继承的 before_action:

      skip_before_action :authenticate_user!, only: [:index, :show]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-02-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-03-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多