title: Rails 4 - can't connect to the table on the database on rails 4
body: <p>I am following a tutorial to learn how to use nested attributes ,I am making a survey , but something is wrong as i cant insert any data in the question table   </p>
  
  <p>that's what I did :  </p>
  
  <p>Question model</p>
  
  <pre><code>class Question &lt; ActiveRecord::Base
      belongs_to :survey
      has_many :answers, dependent: :destroy
  end
  </code></pre>
  
  <hr>
  
  <p>Survey model</p>
  
  <pre><code>class Survey &lt; ActiveRecord::Base
      has_many :questions, dependent: :destroy
      accepts_nested_attributes_for :questions , :reject_if =&gt; lambda { |a| a[:content].blank? }
  end
  </code></pre>
  
  <hr>
  
  <p>views/survey/_form.erb</p>
  
  <pre><code>&lt;%= form_for(@survey) do |f| %&gt;
  
  
   &lt;div class="field"&gt;
    &lt;%= f.label :name %&gt;&lt;br&gt;
    &lt;%= f.text_field :name %&gt;
   &lt;/div&gt;
  
  
  
    &lt;%= f.fields_for :questions do |ff| %&gt;
    &lt;div class="field"&gt;
    &lt;%= ff.label :content , "question"%&gt;&lt;br&gt;
    &lt;%= ff.text_field :content %&gt;
    &lt;/div&gt;
    &lt;% end %&gt; 
  
  &lt;div class="actions"&gt;
    &lt;%= f.submit %&gt;
   &lt;/div&gt;
  
  &lt;% end %&gt;
  </code></pre>
  
  <hr>
  
  <p>SurveysController</p>
  
  <pre><code># GET /surveys/new
    def new
  @survey = Survey.new
  3.times { @survey.questions.new }
  end
  </code></pre>
  
  <hr>
  
  <p>Now when i click submit only the survey name is saved , but no Questions !!
  like this : </p>
  
  <pre><code>2.1.1 :023 &gt; Question.all
  Question Load (0.3ms)  SELECT "questions".* FROM "questions"
  =&gt; #&lt;ActiveRecord::Relation []&gt;
  </code></pre>
  
  <hr>
  
  <p>the create action</p>
  
  <pre><code># POST /surveys
  # POST /surveys.json
  def create
  @survey = Survey.new(survey_params)
  
  respond_to do |format|
    if @survey.save
      format.html { redirect_to @survey, notice: 'Survey was successfully created.' }
      format.json { render action: 'show', status: :created, location: @survey }
    else
      format.html { render action: 'new' }
      format.json { render json: @survey.errors, status: :unprocessable_entity }
    end
  end
  end
  </code></pre>
  
  <hr>
  
  <pre><code> private
  # Use callbacks to share common setup or constraints between actions.
  def set_survey
    @survey = Survey.find(params[:id])
  end
  
  # Never trust parameters from the scary internet, only allow the white list through.
  def survey_params
    params.require(:survey).permit(:name)
  end
  end
  </code></pre>
  
  <hr>
  
  <p>I added another model [answer]</p>
  
  <pre><code>class Answer &lt; ActiveRecord::Base
    belongs_to :question
  end
  </code></pre>
  
  <p>changed Question model to this</p>
  
  <pre><code>class Question &lt; ActiveRecord::Base
  belongs_to :survey
  has_many :answers, dependent: :destroy
  accepts_nested_attributes_for :answers, :reject_if =&gt; lambda { |a| a[:content].blank? }, allow_destroy: true
  end
  </code></pre>
  
  <p>and i changed the survey to</p>
  
  <pre><code># GET /surveys/new
  def new
  @survey = Survey.new
  1.times do
  question = @ survey.questions.build
  2.times { question.answers.build }
  end
  end 
  </code></pre>
  
  <p>now the same previous problem with answers
  how should i handle strong parameters</p>
  
  <p>should it be like this </p>
  
  <pre><code>def survey_params
    params.require(:survey).permit(:name, answers_attributes: [:content]) 
  end
  </code></pre>