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 90405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:52:05+00:00 2026-05-10T22:52:05+00:00

I currently have code in my ApplicationController to check if a user is logged

  • 0

I currently have code in my ApplicationController to check if a user is logged in and has the required access to perform a given action (the tests take place in a before_filter).

I require the same functionality in the views to decide if I should be showing the admin links in a list view, but how do I best avoid duplicating code in the controllers and views?

The way I have chosen to do it now, is to have the user_can_edit_customers? essentially be a wrapper for ‘can_edit_customers?’ on my User class:

ApplicationController:

 class ApplicationController 

And then do something similar in my view helpers.

This way all functionality is encapsulated in the User model but I still need to define wrappers in my controllers and helpers, but are there smarter ways of doing this?

Note, the user stuff is only an example – this also applies to other pieces of functionality.

  • 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. 2026-05-10T22:52:06+00:00Added an answer on May 10, 2026 at 10:52 pm

    I would say do away with the wrappers and just call can_edit_customers? directly on the user object passed to the view.

    If you want to keep them a solution might be to use helper_method in your controller.

    helper_method :current_user, :can_edit_customers?  def current_user     @current_user ||= User.find_by_id(session[:user]) end  def can_edit_customers?     @current_user.can_edit_customers? end 

    This way the method also becomes available in the view.

    <% if can_edit_customers? -%>...<% end -%> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 182k
  • Answers 182k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can use std::getline from <string> to read whole lines… May 12, 2026 at 4:24 pm
  • Editorial Team
    Editorial Team added an answer To specify float call like this: r.Method1(1.1f); Otherwise it'll default… May 12, 2026 at 4:24 pm
  • Editorial Team
    Editorial Team added an answer Try putting an empty CDATA section inside. This should force… May 12, 2026 at 4:24 pm

Related Questions

I've put all of my user-authentication code in one place, namely lib/auth.rb. It looks
Hey, I just began to learn ruby/rails. At the moment, I try to do
My question is as follows: I have a base controller (ASP.Net MVC controller) called
In my app, i currently have all my code separated into a static library,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.