Home > OS >  RubyOnRails : read parameter from the database once
RubyOnRails : read parameter from the database once

Time:09-17

How does this happen in RubyOnRails:
The parameter is stored in the database.
The program needs to read it from the database once upon user login and save them in a global variable.
While the user is working, he uses only this variable, and the program does not read parameter again from the DB, only the next time the user logs on to the system.
How it is implemented.
(edited)
What if there is a solution without sessions?
home_controller : is only one time run in start of user session ?

CodePudding user response:

You can store it in the session hash

class ApplicationController
  def my_variable
    session[:my_variable] ||= MyFile.find(1).my_variable
  end
end  

The app will only need to retrieve it once, the first time a logged in user references the my_variable method. After that, it will use the retrieved value even if the database value is changed.

  • Related