-
Notifications
You must be signed in to change notification settings - Fork 4
Multiple Inheritance
Brad Fults edited this page Oct 18, 2011
·
1 revision
Boxer views support multiple inheritance via the :extends
option, which
simply merges each view into the previous, in order:
Boxer.box(:user) do |box, user|
box.view(:base) { {:name => user.name} }
box.view(:full, :extends => :base) { {:email => user.email} }
box.view(:search, :extends => :base) do
{:last_seen_at => user.last_seen_at.utc.iso8601}
end
box.view(:full_with_time, :extends => [:full, :search]) do
{:current_time => Time.now.utc.iso8601}
end
end
Which would give you:
>> Boxer.ship(:user, User.first, :view => :full_with_time)
=> {:name => "Bob Jones",
:email => "[email protected]",
:last_seen_at => "2011-10-18T19:00:52Z",
:current_time => "2011-10-18T19:02:34Z"}