Forum: Ruby on Rails Syntax to create a dependent relation?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
171ea139761951336b844e708d1547ab?d=identicon&s=25 James Byrne (byrnejb)
on 2008-11-05 21:40
In my controller I have this:

  def new
    load_entity
    @location = @entity.locations.build
    @site = @location.build_site

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @location }
    end
  end

  # GET /locations/1/edit
  def edit
    load_entity
    @location = @entity.locations(params[:id])
  end

  # POST /locations
  # POST /locations.xml
  def create
    load_entity
    @site = @location.build_site(params[:site])
    @location = @entity.locations.build(params[:location].datebalk!)

When I return from my form I have this in params{}

{"user"=>{"userid"=>"authuser",
 "user_id"=>13466,
 "user_name"=>"A. N. Authorized-User"},
 "entity_id"=>"1",
 "commit"=>"Create",
 "authenticity_token"=>"a99e941c6191c6a0897165549bb2606328472187",
 "site"=>{"site_postal_code"=>" ",
 "site_municipality"=>"Hamilton",
 "site_street_number"=>" ",
 "site_region"=>"Ontario",
 "site_name"=>" ",
 "site_country_code"=>"CA",
 "site_building_floor"=>" ",
 "site_street_name"=>"",
 "site_building_name"=>" ",
 "site_building_unit_number"=>" "},
 "location"=>{"location_description"=>" ",
 "superseded_after__dteblk"=>"",
 "effective_from__dteblk"=>"",
 "location_type"=>"MAIN",
 "effective_from"=>"",
 "superseded_after"=>""}}

What is the correct syntax to get the hash "site" and the hash
"location" contained within the hash "params"?
This topic is locked and can not be replied to.