Skip to content

Instantly share code, notes, and snippets.

@royw
Created February 16, 2009 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save royw/64933 to your computer and use it in GitHub Desktop.
Save royw/64933 to your computer and use it in GitHub Desktop.
helpers/global_helpers.rb
# select_belongs_to('State', @address, :state_id, State, :name)
def select_belongs_to(title, base, base_attr_id, type, text_method)
selected = base.send(base_attr_id).to_s
# Merb.logger.info " selected => #{selected}"
select base_attr_id.to_sym,
:label => "#{title}: ",
:text_method => text_method.to_sym,
:value_method => :id,
:collection => type.all.sort do |a,b|
a.send(text_method.to_s) <=> b.send(text_method.to_s)
end,
:selected => selected
end
-----------------
views/addresses/index.html.haml
#show_attributes
#block
%ul
- @addresses.each do |address|
%li= show_attribute(nil, address.to_s, address)
= paginate_helper
#actions
%ul
%li= new_btn rest_resource(@parent, :addresses, :new)
-----------------
views/addresses/_form.html.haml
%p= text_field :street, :label => "Street"
%p= text_field :city_area_district, :label => "City/Area/District"
%p= text_field :city_town_village, :label => "City/Town/Village"
%p= text_field :postal_code, :label => "Postal (zip) Code"
%p= select_belongs_to('State', @address, :state_id, State, :name)
%p= select_belongs_to('Country', @address, :country_id, Country, :name)
%p= text_field :attention, :label => "Attention"
%p= enum_radio_group :type, [:home,:work,:po_box,:other], @address.type
----------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment