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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:20:45+00:00 2026-06-01T11:20:45+00:00

I have the following application_controller method: def current_account @current_account ||= Account.find_by_subdomain(request.subdomain) end Should I

  • 0

I have the following application_controller method:

  def current_account
    @current_account ||= Account.find_by_subdomain(request.subdomain)
  end

Should I be calling it using a before_filter or a helper_method? What’s the difference between the two and what should I consider in terms of the trade-offs in this case?

Thanks.

UPDATE FOR BETTER CLARITY

I’m finding that I can user the before_filter instead of the helper_method in that I’m able to call controller defined methods from my views. Perhaps it’s something in how I arranged my code, so here is what I have:

controllers/application_controller.rb

class ApplicationController < ActionController::Base

  protect_from_forgery

  include SessionsHelper

  before_filter :current_account
  helper_method :current_user

end

helpers/sessions_helper.rb

module SessionsHelper

  private

  def current_account
    @current_account ||= Account.find_by_subdomain(request.subdomain)
  end

  def current_user
    @current_user ||= User.find(session[:user_id]) if session[:user_id]
  end

  def logged_in?
    if current_user
      return true
    else
      return false
    end
  end
end

controllers/spaces_controller.rb

class SpacesController < ApplicationController

  def home
    unless logged_in?
      redirect_to login_path
    end
  end
end

views/spaces/home.html.erb

<%= current_account.inspect %>

In theory, this shouldn’t work, right?

  • 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-01T11:20:46+00:00Added an answer on June 1, 2026 at 11:20 am

    There is no relationship between using before_filter or helper_method. You should use helper method when you have a method in your controller that you would like to reuse in your views, this current_account might be a nice example for helper_method if you need to use it in your views.

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

Sidebar

Related Questions

In application_controller I have the following method: def authorized_for_roles(*roles) roles.each{|role_name| return true if current_user.has_role?(role_name)}
I have the following helper methods in the application_controller.rb for authlogic: def current_user_session return
I have the following index action: class ExpensesController < ApplicationController def index() @expenses =
I have the following: Routes: . . . resources :users do resources :relationships end
In my buy subdomain, I have the following routes: constraints Subdomain::Buy do scope module:
I have the following in my application controller: def is_number?(object) true if Float(object) rescue
I have the following helper method (app/helpers/application_helper.rb): module ApplicationHelper #Return a title on a
I have two rails applications. In the first application i have the following method
I have the following Application tag code in my widget: <mx:Application xmlns:mx=http://www.adobe.com/2006/mxml xmlns:local=* width=100%
I have the following application: I have 1 window. On that window I add

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.