我正在使用设计。当用户“注册”时,他们会转到输入姓名、电子邮件、密码等的页面,然后单击“注册”按钮,如果输入的所有详细信息都正确无误,他们就会进入申请程序,这就是应该发生。
我想做的是添加一个链接,“通过单击“创建帐户”,您确认您接受条款和条件。”在注册页面上。仅此而已,一个简单的链接 - 没有复选框或任何东西。
在我的“注册”页面代码中:
<div class='t_and_c'>
By clicking "Create Account" you confirm that you accept
the <%= link_to "Terms and Conditions.", "static_pages#terms_and_conditions" %>
</div>
但是每当有人单击该链接时,它都会不断重新加载“注册”页面 - 这是它应该做的,因为某处的某些代码告诉应用程序在用户登录之前不要加载任何内容,所以我的问题是:
如何仅针对“条款和条件”这个链接加载我的 terms_and_conditions.html.erb,即使用户没有登录?我想这是一些 before_filter 或 skip_before 过滤器,但我不知道该怎么做。
最佳答案
检查您的 StaticPagesController
以查看是否有任何 before_filter
,这可能是某种身份验证方法,以防止访问者在未登录的情况下阅读。
如果是这样,只需在“terms_and_conditions”方法上添加一个排除选项,例如
before_filter :authorize, :except => :terms_and_conditions
或者
before_filter :authorize, :except => [:terms_and_conditions, :other_method_as_well]
添加
根据 OP 的更新,有 before_filter 但过滤器位于父类 ApplicationController
中。
在这种情况下,您不能简单地在子类中添加另一个 before_filter 来尝试覆盖它。这样做会在过滤器链中再添加一个过滤器。
解决方案是像这样使用skip_before_filter
StaticPagesController < ApplicationController
skip_before_filter :authenticate_user!, only: :terms_and_conditions
方法引用: http://apidock.com/rails/AbstractController/Callbacks/ClassMethods/skip_before_filter
关于ruby-on-rails - Ruby on Rails,即使用户未登录,也会在应用程序中加载页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16496249/