Skip to content

Instantly share code, notes, and snippets.

@roovo
Created December 25, 2008 08:45
Show Gist options
  • Save roovo/39871 to your computer and use it in GitHub Desktop.
Save roovo/39871 to your computer and use it in GitHub Desktop.
# For a sailing club - so they can define their own booking types....
# model: booking_type.rb
class BookingType
include DataMapper::Resource
# properties
property :id, Integer, :serial => true
property :name, String, :nullable => false
property :name_permalink, String # pluralized 'permalinked' version of name
property :boat_type, Enum["yacht", "dinghy"]
end
# in router.rb
match('/admin/:boat_type/:booking_type', :method => "get").defer_to do |request, params|
booking_type = BookingType.first(:name_permalink => params[:booking_type],
:boat_type => params[:boat_type])
unless booking_type.nil?
params.merge(:controller => "admin/boat_bookings", :booking_type => booking_type)
end
end.name(:admin_boat_bookings)
=begin
Then I use a single controller for all the bookings as the actions are common. i.e. if a dinghy
booking type with :name => regatta is added, the url /admin/dinghy/regattas is valid and rotes to
the admin/boat_bookings controller (etc etc for other booking types and for yacht bookings).
...and I actually only wrote this yesterday so haven't yet found out if I can do this in a
'resources' type way to save me adding each of the restful routes in turn - it'll be _really_ be
sweet if I could :)
So far it seems to be working very nicely - the url(:admin_boat_bookings) constructs are working
like a dream.
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment