Hi,

I want to store 6 palettes with color information.

This info should be accessed from a couple of places in my app. From one
controller and from one module I have.

I'm not sure what would be the best way to do it.

In some hashes?

red_palette = { :background => "abcdef", :header => "fedefg" }
blue_paletter = { :background => "12ed34", :header => "abdefg" }
...

In yml?

red_palette:
background: abcdef
header: fedefg

I guess I could make a small module and require it, but then I need to
require it two times. I'm starting to think about memory even though for
this it would be very cheap anyway.

Any advices? I'm on Rails 3.0.5
Thanks.

--
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • comopasta Gr at Sep 29, 2011 at 9:11 am

    comopasta Gr wrote in post #1024192:
    Hi,

    I want to store 6 palettes with color information.
    Would this make sense?

    module Palettes
    DARK_PALETTE = {
    :background => "323232",
    :header => "4d4c4d" }
    end

    Then just:

    require 'palettes'
    puts Palettes::DARK_PALETTE

    I does the trick. I'd like to know it this is a good approach.

    --
    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 post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Robert Walker at Sep 29, 2011 at 1:46 pm

    comopasta Gr wrote in post #1024192:
    I guess I could make a small module and require it, but then I need to
    require it two times. I'm starting to think about memory even though for
    this it would be very cheap anyway.
    Sounds like you're confusing "include" with "require". You could
    "require" a file 50 times, but Ruby would loading it only once.

    If you create a ruby module in would use "include" to include the module
    into a class. But, it seems like a bit of overkill to create a module
    that containing no methods, but only a single constant. I think I'd
    simply put the constant on whatever class is dealing with your color
    pallets.

    Example:

    class MyController
    DARK_PALETTE = {
    :background => "323232",
    :header => "4d4c4d"
    }
    ...
    ...
    end

    Then from anywhere else you need the constant:

    MyController::DARK_PALETTE

    The other, probably better, option would be to setup a custom
    configuration YAML file that includes all your application specific
    constants that gets loaded at startup. That way application wide
    settings are separated from the application's code.

    There was a Railscasts episode a good while back that showed an example
    of setting up a YAML Configuration File:

    http://railscasts.com/episodes/85-yaml-configuration-file

    --
    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 post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Philip Hallstrom at Sep 29, 2011 at 4:54 pm

    On Sep 29, 2011, at 12:41 AM, comopasta Gr wrote:

    Hi,

    I want to store 6 palettes with color information.

    This info should be accessed from a couple of places in my app. From one
    controller and from one module I have.

    I'm not sure what would be the best way to do it.
    Settingslogic
    https://github.com/binarylogic/settingslogic

    -philip

    In some hashes?

    red_palette = { :background => "abcdef", :header => "fedefg" }
    blue_paletter = { :background => "12ed34", :header => "abdefg" }
    ...

    In yml?

    red_palette:
    background: abcdef
    header: fedefg

    I guess I could make a small module and require it, but then I need to
    require it two times. I'm starting to think about memory even though for
    this it would be very cheap anyway.

    Any advices? I'm on Rails 3.0.5
    Thanks.

    --
    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 post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Thorsten Müller at Oct 1, 2011 at 2:38 pm
    A nice way to do this is to place a yml file in the config folder

    like my_app.yml

    and read it in application.rb
    MY_CONFIG = YAML.load(File.read("config/my_app.yml")) unless defined?
    (MY_CONFIG)

    you can define different files for different environments like
    my_app_test.yml
    my_app_development.yml
    my_app_production.yml

    and load with
    MY_CONFIG = YAML.load(File.read("config/my_app_#{Rails.env}.yml"))
    unless defined?(MY_CONFIG)

    On Sep 29, 9:41 am, comopasta Gr wrote:
    Hi,

    I want to store 6 palettes with color information.

    This info should be accessed from a couple of places in my app. From one
    controller and from one module I have.

    I'm not sure what would be the best way to do it.

    In some hashes?

    red_palette = { :background => "abcdef", :header => "fedefg" }
    blue_paletter = { :background => "12ed34", :header => "abdefg" }
    ...

    In yml?

    red_palette:
    background: abcdef
    header: fedefg

    I guess I could make a small module and require it, but then I need to
    require it two times. I'm starting to think about memory even though for
    this it would be very cheap anyway.

    Any advices? I'm on Rails 3.0.5
    Thanks.

    --
    Posted viahttp://www.ruby-forum.com/.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedSep 29, '11 at 7:41a
activeOct 1, '11 at 2:38p
posts5
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase