For a number of my models I have many constant key value pairs
(sometimes dozens). I have considered putting them in the model but it
ends up creating a very cluttered model file. Is there an approvaed
approach to having an external data file that is associated with a
model? Should I use a yaml file of the same name? xml? csv?
Recommendations are appreciated.
For a number of my models I have many constant key value pairs
(sometimes dozens). I have considered putting them in the model but it
ends up creating a very cluttered model file. Is there an approvaed
approach to having an external data file that is associated with a
model? Should I use a yaml file of the same name? xml? csv?
Recommendations are appreciated.
For a number of my models I have many constant key value pairs
(sometimes dozens). I have considered putting them in the model but it
ends up creating a very cluttered model file. Is there an approvaed
approach to having an external data file that is associated with a
model? Should I use a yaml file of the same name? xml? csv?
Recommendations are appreciated.
How about Ruby? Just define some constants and pull them in at
runtime. You can put things in lib/ and then require them from your
model file(s), or from the bottom of environment.rb. For example, you
could create a file called extra_data.rb:
module ExtraData
COLORS = %w{ red orange yellow }
end
Then in your model file:
require ‘extra_data’
now you have access to ExtraData::COLORS.
David
–
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (Ruby for Rails)
(See what readers are saying! http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.