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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:46:08+00:00 2026-06-13T03:46:08+00:00

I have a rails setup that is something like this. app/service/TestService.rb class TestService def

  • 0

I have a rails setup that is something like this.

app/service/TestService.rb

class TestService

  def self.doSomething
    return 'Hello World!'
  end

end

I am using this file in the controller.

require 'TestService'

class IndexController < ApplicationController

  def index
    @message = TestService.doSomething
  end

end

I also added this in application.rb inside the config folder, so that rails autoload classes in service folder.

config.autoload_paths += %W(#{config.root}/app/service)

But the application doesn’t seem to pick up updates to TestService class. How can I fix this, so that changes in TestService class show up without restarting the server.

  • 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-13T03:46:09+00:00Added an answer on June 13, 2026 at 3:46 am

    Do not use require when attempting to load a file containing a reloadable constant.

    Normally, you will not need to do anything special to be able to use that constant. You will just use the constant directly, without having to use require or anything else.

    But if you want to be squeaky clean with your code, ActiveSupport provides you with a different method that you can use to load these files: require_dependency.

    require_dependency 'test_service'
    
    class IndexController < ApplicationController
      ...
    end
    

    Although it’s confusing that you would attempt to be squeaky clean and explicitly load the file containing TestService but not explicitly load the file containing ApplicationController….

    You do not need to change the autoload_paths config.


    Update 1

    In order to let Rails find and load your constants (classes and modules), you need to do the following:

    You must be sure that every reloadable constant in your application is in a file with the right filename. The file must always be in some subdirectory of app, such as app/models or app/services or any other subdirectory. If the constant is named TestService, the filename must end with test_service.rb.

    The algorithm is: "TestService".underscore + ".rb" #=> "test_service.rb".

    filename_glob = "app/*/" + the_constant.to_s.underscore + ".rb"
    

    So if the constant is TestService, then the glob is app/*/test_service.rb. So sticking the constant in app/services/test_service.rb will work, as will app/models/test_service.rb, although the latter is bad form. If the constant were SomeModule::SomeOtherModule::SomeClass, you would need to put the file in app/*/some_module/some_other_module/some_class.rb.

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

Sidebar

Related Questions

I'm trying setup a Rails app that will be something like a game. The
I have a rails project that I would like to set up email notifications
I have setup some simple associations in my rails app: resources :properties do resources
I have my models & associations currently setup like so: class User < ActiveRecord::Base
Currently I have a Rails 3 app that subscribes new users up to MailChimp.
I have models of one of my projects set up to something like this
I have a Rails 3.1 app that I want to create an API for.
I have a small rails app that is using acts_as_list to implement drag and
I have a rails app that shows statistics based on an employee's daily production.
I have a rails app (Rails 3.0) that I need to temporarily take out

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.