2014-10-17 40 views
1

我的应用程序出现小问题。有条件地注册导轨4

而不是让我的访问者登录的选项,它是重定向访问我的应用程序的每个人立即登录或他们无法导航任何其他选项卡。

为了进一步澄清我的application.html.erb文件我有以下代码:

<% if user_signed_in? %> 
    Logged in as <strong><%= current_user.email %></strong> 
    <br> 
    <br> 
    <%= link_to 'Edit profile', edit_user_registration_path, :class => 'navbar-link' %> | 
    <%= link_to "Logout", destroy_user_session_path, method: :delete, :class => 'navbar-link' %> 


<% else %> 
    <%= link_to "Sign up", new_user_registration_path, :class => 'navbar-link' %> | 
    <%= link_to "Login", new_user_session_path, :class => 'navbar-link' %> </p> 
<% end %> 

如果有人能帮助我指导我需要有在牌子,上面路线作为一个选项,而不是作为我的应用程序的所有访问者的默认值,将不胜感激。

在我application_controller.rb文件中的代码如下:

class ApplicationController < ActionController::Base 
# Prevent CSRF attacks by raising an exception. 
# For APIs, you may want to use :null_session instead. 
protect_from_forgery with: :exception 


before_action :authenticate_user! 
end 
+0

您可以发布相关的应用程序控制器代码? – Jeremiah 2014-10-17 19:55:51

+0

Jeremiah谢谢你指出,我也要添加application_controller.rb文件的代码 – 2014-10-17 19:57:24

回答

3

在您不想要强制认证控制器,添加skip_filter声明:

skip_filter :authenticate_user! 

如果您有一个控制器,其中只有一些操作应该是未认证的(例如索引和显示操作):

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

或者你可以做,除了某几个所有的动作打开:

skip_filter :authenticate_user!, except: [:create, :update] 
+0

是的,在你的application_controller.rb文件中寻找这个代码 – Peege151 2014-10-17 20:18:09

+0

这个工程!谢谢 – 2014-10-17 23:31:18