Ruby on Rails Model Association with params -
here model
class location has_many :areas end class area belongs_to :location end
the controller
def create @area = area.new(area_params) @area.location_id = session[:current_location] end
how can associate model when i'll create new area? this?
def create @area = @location.areas.create(area_params) end
be sure set location_id attribute upon creation. should included in params. if provide full controller file more specific.
yes, include area_params
can include location_id
, should column in database.
Comments
Post a Comment