title: Editing nested attribute/model rails
body: <p>Hello I have being using @jordanhudgens nested attribute tutorial to build a rails app to handle @sites and @site_assets. I can add new @site_assets and delete them, but I am struggling to edit them.</p>
  
  <p>I get the following error when I try to edit</p>
  
  <pre><code>ArgumentError in Sites::SiteAssets#edit
  Showing app/views/sites/site_assets/_form.html.erb where line #1 raised:
  
  First argument in form cannot contain nil or be empty
  Extracted source (around line #1):
  
  &lt;%= form_for [@site, @site_asset] do |form| %&gt;
  
    &lt;div class="field"&gt;
      &lt;%= form.label :name %&gt;
      &lt;%= form.text_field :name, id: :site_asset_name %&gt;
    &lt;/div&gt;
  
  Trace of template inclusion: app/views/sites/site_assets/edit.html.erb
  </code></pre>
  
  <p>Site Show Page that shows the Site_Asset loop including the edit button</p>
  
  <pre><code>&lt;tbody&gt;
    &lt;% @site_assets.each do |site_asset| %&gt;
      &lt;tr&gt;
        &lt;td&gt;&lt;%= site_asset.name %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= site_asset.asset_type.name %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= site_asset.manufacturer.name %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= site_asset.model %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= site_asset.serial %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= site_asset.location.name %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= site_asset.installed %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= site_asset.condition %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= link_to 'Edit', edit_site_site_asset_path(site_id: @site.id, id: site_asset.id) %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= link_to 'Delete', [@site, site_asset], method: :delete, confirm: 'are you sure?'%&gt;&lt;/td&gt;
      &lt;/tr&gt;
    &lt;% end %&gt;
    &lt;/tbody&gt;
  </code></pre>
  
  <p>views/sites/site_assets/_form.erb.html</p>
  
  <pre><code>&lt;%= form_for [@site, @site_asset] do |form| %&gt;
  
    &lt;div class="field"&gt;
      &lt;%= form.label :name %&gt;
      &lt;%= form.text_field :name, id: :site_asset_name %&gt;
    &lt;/div&gt;
    &lt;div class="field"&gt;
      &lt;%= form.label :manufacturer_id %&gt;
      &lt;%= form.collection_select :manufacturer_id, Manufacturer.all, :id, :name %&gt;
    &lt;/div&gt;
  
    &lt;div class="field"&gt;
      &lt;%= form.label :model %&gt;
      &lt;%= form.text_field :model, id: :site_asset_model %&gt;
    &lt;/div&gt;
  
    &lt;div class="field"&gt;
      &lt;%= form.label :serial %&gt;
      &lt;%= form.text_field :serial, id: :site_asset_serial %&gt;
    &lt;/div&gt;
  
    &lt;div class="field"&gt;
      &lt;%= form.label :location_id %&gt;
      &lt;%= form.collection_select :location_id, Location.all, :id, :name %&gt;
    &lt;/div&gt;
  
    &lt;div class="field"&gt;
      &lt;%= form.label :asset_type_id %&gt;
      &lt;%= form.collection_select :asset_type_id, AssetType.all, :id, :name %&gt;
    &lt;/div&gt;
  
    &lt;div class="field"&gt;
      &lt;%= form.label :installed %&gt;
      &lt;%= form.date_select :installed, id: :site_asset_installed, class: 'datepicker' %&gt;
    &lt;/div&gt;
  
    &lt;div class="field"&gt;
      &lt;%= form.label :condition %&gt;
      &lt;%= form.select :condition, SiteAsset.conditions.keys %&gt;
    &lt;/div&gt;
  
  
    &lt;div class="actions"&gt;
      &lt;%= form.submit %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Site_Asset Model</p>
  
  <pre><code>class SiteAsset &lt; ApplicationRecord
    belongs_to :site
    belongs_to :asset_type
    belongs_to :location
    belongs_to :manufacturer
  
    enum condition: { New: 4, Good: 3, Ok: 2, Poor: 1 }
  end
  </code></pre>
  
  <p>controllers/site/Site_Assets_Controller</p>
  
  <pre><code>class Sites::SiteAssetsController &lt; ApplicationController
  
    # GET /site_assets
    # GET /site_assets.json
    def index
      @site_assets = SiteAsset.all
    end
  
    # GET /site_assets/1
    # GET /site_assets/1.json
    def show
    end
  
    # GET /site_assets/new
    def new
      @site = Site.find(params[:site_id])
      @site_asset = SiteAsset.new
    end
  
    # GET /site_assets/1/edit
    def edit
    end
  
    # POST /site_assets
    # POST /site_assets.json
    def create
      @site = Site.find(params[:site_id])
      @site_asset = SiteAsset.new(site_asset_params)
      @site_asset.site = @site
  
      respond_to do |format|
        if @site_asset.save
          format.html { redirect_to @site, notice: 'Site asset was successfully created.' }
          format.json { render :show, status: :created, location: @site_asset }
        else
          format.html { render :new }
          format.json { render json: @site.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # PATCH/PUT /site_assets/1
    # PATCH/PUT /site_assets/1.json
    def update
  
      @site = Site.find(params[:site_id])
      @site_asset = SiteAsset.find(params[:id])
  
      respond_to do |format|
        if @site_asset.update(site_asset_params)
          format.html { redirect_to @site, notice: 'Site asset was successfully updated.' }
          format.json { render :show, status: :ok, location: @site_asset }
        else
          format.html { render :edit }
          format.json { render json: @site.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # DELETE /site_assets/1
    # DELETE /site_assets/1.json
    def destroy
      @site = Site.find(params[:site_id])
      @site_asset = SiteAsset.find(params[:id])
  
      @site_asset.destroy
      respond_to do |format|
        format.html { redirect_to @site, notice: 'Site asset was successfully destroyed.' }
        format.json { head :no_content }
      end
    end
  
    private
      # Use callbacks to share common setup or constraints between actions.
      def set_site_asset
        @site_asset = SiteAsset.find(params[:id])
      end
  
      # Never trust parameters from the scary internet, only allow the white list through.
      def site_asset_params
        params.require(:site_asset).permit(:name, :model, :serial, :installed, :site_id, :manufacturer_id, :asset_type_id, :location_id, :condition)
      end
  end
  </code></pre>
  
  <p>As I said the create and delete method both work perfectly. It is just the edit that has got me</p>