How do I redirect to different display paths using Rails and Currency

advertisements

I am using rails3 and gem devise and i have two roles admin and customer and i want after user

sign out admin should redirect to different path and customer should redirect to different path

when sign out..


You can get your desired functionality by using devise method after sign_out path.

but before you define these methods in application helper.

def is_admin?(user)
  admin_role = Role.find(:first, :conditions => ["name = ?", "admin"])
  return user.roles.include?(admin_role)
end

def is_customer?(user)
  admin_role = Role.find(:first, :conditions => ["name = ?", "customer"])
  return user.roles.include?(admin_role)
end

After that include application helper in application controller and define this method

def after_sign_out_path_for(resource_or_scope)
  if is_admin?(current_user)
    home_path = "/admin/users/sign_in"
  elsif is_customer?(current_user)
    home_path = "/customer"
  end
    respond_to?(home_path, true) ? send(root_path) : home_path

end

Hope it will work fine !!!