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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:04:53+00:00 2026-06-14T02:04:53+00:00

I am writing this widget that is to be included with a single page

  • 0

I am writing this widget that is to be included with a single page of the site, so I don’t see a reason to declare what I am doing in the ApplicationController. However, this new widget does have a fair amount of complexity to it, so I want to keep it separate from the controller that normally handles this page since that controller already has quite the bit of complexity in it. I originally figured in my design I could just make a helper module for the controller and keep most of the widget logic there.

I am trying to write this helper module, but then I realized that there is a particular array I need to be able to initialize from a single location, but multiple methods need access to it and it needs to be insured that it is initialized before any other method makes calls to this array. Is there a way to do something similar to a before_filter in such a module where I can ensure this variable is initialized before use or is there a better overall way of approaching this that is the “Rails way”?

  • 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-14T02:04:55+00:00Added an answer on June 14, 2026 at 2:04 am

    I think you can create a new class and instantiate it in the before_filter or your controller.
    Not sure what you want to achieve but an example could be :

    class MyArrayBuilder
      def initialize(some, param)
        #something
      end
    
      def get_array
        return my_array
      end
    end
    
    class SomethingsController < ApplicationController
    
      before_filter :build_array
    
      def build_array
        @array = MyArrayBuilder.new(some, param).get_array
      end
    end
    

    Then you pass the @array variable to your helper.

    I’m not sure there is a “Rails way” of doing what you want : Rails as a lot of convention but when you start to care a lot about design and DRY, I believe it’s better to think in term of good practice for Oriented Object Programming than Rails convention.

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

Sidebar

Related Questions

I'm writing an App and an accopmanying widget that needs data. This data is
I am writing a web page widget for my company. This widget must inject
I'm writing a widget that pulls data from a web page every 5 minutes,
I am writing a widget template, which will be included in a page where
I've had trouble writing this code. I'm supposed to make a function that can
I face a very serious situation. By writing this question I hope that really
I'm writing an image viewer as a custom Qt widget (see: https://github.com/dov/Qviv ) and
I am writing a jquery UI widget that simply wraps the bootstrap popover plugin,
Im writing little widget that shows time, date.. with many settings. And I want
I am writing a simple widget that renders a canvas participation graph just like

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.