Now Serving At The Rails Diner

New Instance

(Create a new instance of your Guest method.)

@guest  =  Guest.new

New Instance with Side of Association

(This associates this guest with their meal. Note the plural “meals“.)

@meal = @guest.meals.build

New Instance with Side of Association (no split plates)

(Despite the plural “meals”, each meal may belong to only one guest. No split plates! This will assign the id of @guest in the @meal’s guest_id column.)

@meal = @guest.build_meals

 

More on Active Record Associations: here. Thank yous to vihnboy and Duplex.

About

A typographic, designological, visulicious extravaganza!

Posted in Rails && Sinatra && Camping, Ruby, Useful Code