title: Insert data into database from controller Ruby On Rails?
body: <p>In my <strong>def Create funciton</strong> in casting_controller. I create an Casting object and save it. this is ok, but i also want to create a LinkCastingToModel object, insert data to it from my controller, but when i check, the data is always nil. How can i insert data into it</p>
  
  <pre><code>def create
    @casting = Casting.new(casting_params)
    @casting.models_booked = 0
    link = LinkModelAndCasting.new
    link.client_id = @casting.id
    link.save
    # link_model_and_casting = LinkModelAndCasting.new(:casting_id =&gt; @casting.id)
    # link_model_and_casting.save
  
    respond_to do |format|
      if @casting.save
        format.html { redirect_to @casting, notice: 'Casting was successfully created.' }
        format.json { render :show, status: :created, location: @casting }
      else
        format.html { render :new }
        format.json { render json: @casting.errors, status: :unprocessable_entity }
      end
    end
  end
  </code></pre>
  
  <p>I use postgresql, thanks.</p>