views:

8

answers:

0

I am trying to create a consolidated Application Constants file which populates various dropdowns in different parts of the application. I am using the very effective active_hash gem for this (http://github.com/zilkey/active_hash)

The application constants (named def_constants)file typically has the following yaml structure

####### company_type ##############

company_type: { "Private, Independent"  : 1,
                "Private, Subsidiary"   : 2,
                "Public, Parent"        : 3,
                "Public, Subsidiary"    : 4}
####### company_status ##############
company_status: {
                    Active                : 1,
                    Inactive              : 2,
                    Acquired or merged    : 3 }
...
...
...

I also created a list.rb which has the following code

class List < ActiveYaml::Base

set_root_path "#{RAILS_ROOT}/config/constants/"
set_filename "def_constants"

fields :company_type , :company_status

end

I am not trying to use this structure in various forms. In a particular form I am doing this

  <p>
    <%= f.label :company_type %><br />
   <%= f.select :company_type,  List.find_by_company_type.attributes %>
  </p>

However this does not really work. The two activerecord queries down below both fail

 >>List.find_by_company_type.attributes

 /usr/lib/ruby/gems/1.8/gems/active_hash-0.8.2/lib/active_hash/base.rb:181:
 warning: multiple values for a block
 parameter (0 for 1)  from (irb):1
 => {:"Private, Subsidiary"=>2, :"Public, Parent"=>3, :"Private,
 Independent"=>1, :"Public,
 Subsidiary"=>4, :id=>1}


>>List.find_by_company_status.attributes

 /usr/lib/ruby/gems/1.8/gems/active_hash-0.8.2/lib/active_hash/base.rb:181:
 warning: multiple values for a block
 parameter (0 for 1)  from (irb):1
 => {:"Private, Subsidiary"=>2, :"Public, Parent"=>3, :"Private,
 Independent"=>1, :"Public,
 Subsidiary"=>4, :id=>1}

What is the best way to resolve this. All I want to do is have a nested set of hashes in a yml file for me to access at various places of the application? Can this be done in a much simpler/better way?