error in relation between two models - ruby on rails 3 <p>please I need help ! seems like my association doesn't work correctly but i cant find what's wrong. i have a relation between student and guardian , student has many guardians and guardians belongs to student</p> <p>i can't get the admission number which inserted in student form , to the guardians form , seems like no relation but i cant solve it !</p> <p>I Dont knw why users down vote my question ! :D i just cant make this work so i asked for a help :O</p> <p>students_controller.rb</p> <pre><code>class StudentsController &lt; ApplicationController def index @student = Student.all end def show @student = Student.find(params[:id]) end def new @student = Student.new end def create @student = Student.new(params[:student]) if @student.save flash[:success] = ' Student Record Saved Successfully. Please fill the Parent Details.' redirect_to new_guardian_url else flash.now[:error] = 'An error occurred please try again!' render 'new' end end def edit end end </code></pre> <p>guardians_controller.rb</p> <pre><code>class GuardiansController &lt; ApplicationController def index end def show end def new @guardian = Guardian.new end def edit end end </code></pre> <p>student.rb</p> <pre><code>class Student &lt; ActiveRecord::Base attr_accessible :address_line1, :address_line2, :admission_date, :admission_no, :birth_place, :blood_group, :city, :class_roll_no, :date_of_birth, :email, :first_name, :gender, :language, :last_name, :middle_name, :phone1, :phone2, :post_code, :religion, :country_id, :nationality_id belongs_to :user belongs_to :country belongs_to :school belongs_to :batch belongs_to :nationality , class_name: 'Country' has_many :guardians has_many :student_previous_subject_marks has_one :student_previous_data end </code></pre> <p>guardian.rb</p> <pre><code>class Guardian &lt; ActiveRecord::Base attr_accessible :city, :dob, :education, :email, :first_name, :income, :last_name, :mobile_phone, :occupation, :office_address_line1, :office_address_line2, :office_phone1, :office_phone2, :relation belongs_to :user belongs_to :country belongs_to :school belongs_to :student end </code></pre> <p>guardians/new.html.erb</p> <pre><code>&lt;h1&gt;Admission&lt;/h1&gt; &lt;h4&gt;Step 2 - Parent details&lt;/h4&gt; &lt;div class="row-fluid"&gt; &lt;div class="span4 offset1 hero-unit"&gt; &lt;%= form_for @guardian do |f| %&gt; &lt;% if @guardian.errors.any? %&gt; &lt;div id="error_explanation"&gt; &lt;div class="alert alert-error"&gt; The form contains &lt;%= pluralize(@guardian.errors.count, 'error') %&gt; &lt;/div&gt; &lt;ul&gt; &lt;% @guardian.errors.full_messages.each do |msg| %&gt; &lt;li&gt;* &lt;%= msg %&gt;&lt;/li&gt; &lt;% end %&gt; &lt;/ul&gt; &lt;/div&gt; &lt;% end %&gt; &lt;fieldset&gt; &lt;div class="field"&gt; &lt;%= f.label 'Student Admission number' %&gt; &lt;%= f.text_field @guardian.student.admission_no %&gt; &lt;/div&gt; </code></pre>