Jafor Rockman
Jafor Rockman

Reputation: 25

Keep an action in view post out of devise authentication

I have installed devise gem for authentication. I have created a scaffold named Members. I have put

before_filter :authenticate_user!

at the top of the Members controller. but I want to make

Member.Show

action to be out of the authentication. I mean with out signing in any one can see the Members profile.

Thanks

Upvotes: 0

Views: 56

Answers (3)

Bastien Léonard
Bastien Léonard

Reputation: 61803

You can add this line in your controller (typically, at the beginning):

class MembersController < YourBaseController
  # ...

  skip_before_filter :authenticate_user!, only: [:show]

  # ...
end

Upvotes: 1

Rajarshi Das
Rajarshi Das

Reputation: 12340

You can simply do

class MembersController < ApplicationController
   skip_before_filter :authenticate_user!, only: [:show]

   #rest of the codes
   def show
     #show codes
   end
end

Upvotes: 0

Katherine
Katherine

Reputation: 171

The most elegant way is to use an except filter for this:

class MembersController
  ...
  before_filter :authenticate_user!, except: :show
  ..
end

This way all of your logic around the filter is contained in one place. You can also pass in an array of actions to exclude:

class MembersController
  ...
  before_filter :authenticate_user!, except: [:show, :another_action]
  ..
end

For more see: http://apidock.com/rails/ActionController/Filters/ClassMethods/before_filter

Upvotes: 0

Related Questions