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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:53:26+00:00 2026-06-02T01:53:26+00:00

I am working on releasing my first Gem for Rails. It is pretty simple,

  • 0

I am working on releasing my first Gem for Rails. It is pretty simple, but I am needing to provide some access to setting config options. I’d like to have the user put something in ‘config/initializers’ and tie into that with my gem.

So, the question is: Is there a best-practice for providing config options in a Rails gem?

  • 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-02T01:53:28+00:00Added an answer on June 2, 2026 at 1:53 am

    In an engine I help develop, Forem, we use mattr_accessors on the top-level constant like this:

    lib/forem.rb

    module Forem
      mattr_accessor :user_class, :theme, :formatter, :default_gravatar, :default_gravatar_image,
                     :user_profile_links, :email_from_address, :autocomplete_field,
                     :avatar_user_method, :per_page
    ...
    

    Then inside config/initializers we ask users to set them up like this:

    Forem.user_class = 'User'
    Forem.autocomplete_field = :login
    

    With a short gem name, there’s not much difference between this solution and the other one I will propose.


    Solution #2

    Still use mattr_accessors on your top-level constant but offer a config method on this module that takes a block and yields the object:

    module ReallyComplicatedGemName
      mattr_accessor :....
      def self.config(&block)
        yield(self)
      end
    ...
    

    This way people can do:

    ReallyComplicatedGemName.config do |config|
      config.user_class = "User"
      ...
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working with MS Access for the first time and coming across a few problems
I'm working on my first real-world Rails project. So far, I'm mostly mashing up
I'm working on releasing my first app and I have been using a self
I am working on releasing an app that will greatly benefit from using the
I am working on my first NASM program, and while trying to figure out
I'm working on my first MVC project. I have very little knowledge on jscript,
The first part is now working [ I have the following which just seems
I am currently working on my first app for the iPhone, I am almost
I'm using WMEncoder for screen recording. At the first time everything is working properly,
First, let me say I've been working with WPF for about a week. I

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.