2014-10-17 63 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