Reputation: 135
I am having a minor issue with my application.
Instead of giving my visitors the option to sign in, it is redirecting everyone who visits my application to sign in immediately or they are unable to navigate any other tabs.
For further clarification in my application.html.erb file i have the following code:
<% 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 %>
If someone could assist me in directing which route I need to take to have the sign in as an option and not as a default for all visitors to my application it would be greatly appreciated.
In my application_controller.rb file the code is as follows:
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
Upvotes: 1
Views: 47
Reputation: 24337
In the controllers that you do not want to force authentication in, add a skip_filter
declaration:
skip_filter :authenticate_user!
If you have a controller, where only some of the actions should be non-authenticated (index and show actions for example):
skip_filter :authenticate_user!, only: [:index, :show]
Or you can make all the actions open except for certain ones:
skip_filter :authenticate_user!, except: [:create, :update]
Upvotes: 3