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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:34:33+00:00 2026-05-19T22:34:33+00:00

I am using Ruby on Rails 3 and I would know in which case

  • 0

I am using Ruby on Rails 3 and I would know in which case is good to use Modules.

I have a controller including a lot of private methods that I use in this way:

class UsersController < ApplicationController

  def update
    params[:option1] = get_user_option1
    params[:option2] = get_user_option2


    if params[:option2]
      params[:saving_success] = update_user
    end

    ...

    if params[:saving_success] 
      flash[:notice] = another_method_1
    else
      flash[:error] = another_method_2
    end
  end


    private

      def update_user
        if params[:option1] == something
          @user.save
        end
      end

      def another_method_1
        params[...] = ...
      ...
  end

As you can see, in private methods I have things like ActiveRecords and params methods. I know that in a Module you can not use those ActiveRecords or params methods directly, but you can pass they as arguments like in this example:

# In the controller file
class UsersController < ApplicationController
  include Users

  def update
    params[:option] = "true"
    @users = Users.find(1)
    Users::Validations.name (@user, params[:option])
    ...
  end
end

# In the module file
module Users
  module Validations
    def Validations.name(user, param)
      user == "Test_name" if param
      # Normally the following is not possible:
      # @user == "Test_name" if params[:option]
    end
  end
end

So, what do you advice in my case? Is it good to use separate Modules?


Questions of secondary importance (for now…):

  1. What about performance?

P.S. I: Pay no attention to the simplicity of the examples. They are written just to understand my dilemma about passing ActiveRecords and params methods.

P.S. II: If you need to have some other information, let me know.

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

    Modules have 2 primary purposes :

    1. Namespacing
    2. Mixins

    Module Namespacing is generally used to organize code better and to facilitate safer and coherent scoping.

    But modules find their major use as mixins. Its Ruby’s way of providing multiple inheritance. For example, lets say you have methods that need to be accessed across Classes (for instance across different models/controllers etc). Instead of repeating those methods in each class, that don’t necessarily apply just to that class, you abstract those methods out into a module and include or extend the module in the appropriate class.

    It depends on how tightly coupled a module is with the app directory to decide as to
    where to store the module. A few patterns in storing modules :

    1. The /lib directory, if the module does not particularly ‘interact’ with app/.
    2. The app/models directory, but may cause confusion with actual ActiveRecord models.
    3. 37 Signals introduced a pattern of treating them as ‘concerns’ and storing them in app/concerns.

    However, if in case you have a method that you’re using just for your Users Controller, it is recommended that you put that code into your User model, because that’s where the business logic for the ‘User’ should be.

    By ‘ActiveRecords’, I’m assuming you mean Model classes (such as User).
    You CAN access model classes and perform ActiveRecord operations (such as User.find(:all)) on them in modules.

    However, as you guessed right, you can’t use params, you’ll have to pass that as an argument to the module’s method.

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

Sidebar

Related Questions

I am using Ruby on Rails 3 and I would like to know some
I am using Ruby on Rails 3 and I would like to know what
I am using Ruby on Rails 3 and I would like to know some
I am using Ruby on Rails 3 and I would like to know some
I am using Ruby on Rails 3 and I would like to know what
I am using Ruby on Rails 3 and I would like to know what
I am using ruby on rails with a MySQL backend. I have a table
I have been using ActiveResource in my Ruby on Rails applications for some time,
I have done a few projects using Ruby on Rails. I am going to
I would like to create something like this using ruby on rails. Im not

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.