Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5949279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:13:35+00:00 2026-05-22T17:13:35+00:00

I have been following Ryan Bates railcasts to get an admin authentication system to

  • 0

I have been following Ryan Bates railcasts to get an admin authentication system to display certain options if the currently logged in user is an admin or not.

The def admin? method works but only if I set it to true or false in the code. True displays all the options and false hides them.

I have tried:
current_user[:username] == 'dave' which works until the user changes to someone else then it gives a no method error .

and session[:username] == 'dave' gives no errors but sets the admin? method to false on all users including ‘dave’.

What should I be putting into my admin? method? Ideally I would like it to see if both the username and passsword matches then returns true.

Any help would be much appreciated!

application controller

class ApplicationController < ActionController::Base
  helper :all # include all helpers, all the time
  protect_from_forgery # See ActionController::RequestForgeryProtection for details

  helper_method :admin?

  protected

  def authorize
    unless admin?
      flash[:error] = "not authorized!"
      redirect_to venues_path
      false
    end
  end

  def admin?
    true
    #false
  end
end

routes

Go::Application.routes.draw do

  get "log_in" => "sessions#new", :as => "log_in"
  get "log_out" => "sessions#destroy", :as => "log_out"
  get "sign_up" => "users#new", :as => "sign_up"
  root :to => "users#new"

  resources :sessions
  resources :users
end

sessions controller

class SessionsController < ApplicationController

  def create
    user = User.authenticate(params[:username], params[:password])
    if user
      session[:user_id] = user.id
      redirect_to venues_path, :notice => "Logged in!"
    else
      flash.now.alert = "Invalid username or password"
      render "new"
    end
  end

  def destroy
    session[:user_id] = nil
    redirect_to venues_path, :notice => "Logged out!"
  end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:13:36+00:00Added an answer on May 22, 2026 at 5:13 pm

    I think you should look into using CanCan, a gem written by Ryan Bate.

    https://github.com/ryanb/cancan

    You’ll learn how to set abilities and can do things like:

    if can? :manage, :all
       # Admin stuff
    else
       # Non-admin stuff
    end
    

    You’ll also be able to check abilities on specific models.

    if can? :manage, Project
       # bla bla
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been following this tutorial in order to get username authentication with transport
I currently running into trouble with spring security, I have been following the two
I've been following through Ryan Bates' railscast on using cancan but am stumped as
I'm currently creating a WPF app in C# and have been following this diagram
I'm new to Cucumber and have been stepping through a railscast by Ryan Bates.
I have been following some MVC tutorials that connect to a sql mdf database
I have been following the usage of JavaScript for the past few years, and
I have been following the following post on using multiple ItemTemplates in a ListView
Hi I am quite new to php but i have been following some tutorials
Recently I have started playing with jQuery, and have been following a couple of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.