Ruby on Rails Tuesday, October 21, 2014

Hi,
I've code like this

x_data = Model.where(column: 'xyz')

and I wanted to use 'x_data' everywhere like models, controllers,
helpers, etc.

I used in this way

module Global
X_DATA = Model.where(column: 'xyz')
end

but when using Global::X_DATA it is firing query every time.

Where should I write this to use it everywhere and query should not be
fired more than once.

add this in initializers is a good practice?

Please help.

Thanks in advance.
Avantec

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/126984f291818c4ea6cf113228caf379%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment