ruby on rails - Is it possible to exclude unsigned-in user if URL contains particular parameter when using Devise? -


there's url this

example.com/users/1376 

anyone can see page if user not signed-in.

there's url this

example.com/users/1376?mode=1 

only signed-in user can see page, otherwise user redirected sign-in page(new_users_session_path)

could this?

before_filter :authenticate_user!, :only => [:show(params[:mode]=1)]  

if not, please show me how solve this.

thanks

for rails 3.2

before_filter :redirect_user, :only => :show

for rails 4

before_action :redirect_user, :only => :show

def redirect_user            if params[:mode] == 1 && current_user         redirect_to user_path(id: params[:id], mode: 1) #example.com/users/1376?mode=1  elsif !current_user && params[:mode].blank?    redirect_to user_path(id: params[:id])   else     redirect_to new_users_session_path  end      end   

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -