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

  • Home
  • SEARCH
  • 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 7844185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:47:54+00:00 2026-06-02T16:47:54+00:00

I am working on adding authorizations to an app I am building and I

  • 0

I am working on adding authorizations to an app I am building and I have a question. I have added an :admin column to my User table and set it as a boolean. In my controller I have added this code:

class ShipsController < ApplicationController

  def index
    ships = Ship.all
    @ships = ships.sort_by { |v| [v[:empire_image], v[:cost]] }
    if current_user.admin == true
      respond_to do |format|
        format.html # index.html.erb
        format.json { render json: @ships }
      end
    else
      respond_to do |format|
        format.html { redirect_to root_path }
      end
    end
  end

It looks like I will have to add this to all of my actions and this seems wrong. My question is, is doing it this way insecure or just more work for myself but fine.

Also I am using the authentication from railstutorial.org and am wondering if a library like cancan would work well with that.

Thanks for your time,
Nick

  • 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-06-02T16:47:55+00:00Added an answer on June 2, 2026 at 4:47 pm

    This way is not insecure, it’s just clutter your controllers, at least consider to use a before_filter to authorize your actions.

    Maybe for a simple application use a 3rd party authorization gem could seems overkill but move the authorization rules in a single place is a very good thing (the ability.rb file in the case of CanCan).

    You can use CanCan with that authentication system, CanCan just expects a current_user method to exist in the controller.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm adding an auto increment column (called rowNum) to my table and it's working
I'm currently working on adding memcache to an app running on GAE/J. I have
I'm working on adding user submitted comments to a personal project. Comments have a
I am working on adding In-App purchases to my app. I am able to
I am working on adding iCloud support to my income tracking app myIncome that
I have a Group resource that I'm trying to set up with proper authorizations.
I am working with adding up user's scores based on their checks in a
I'm planning out adding Facebook integration to a web app I'm working on. For
I'm working on adding globalization to my product cataloge and I have made it
So, I have been working on adding BitmapImages to a ListBox for pretty much

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.