-1

助けてください!関連付けが正しく機能していないようですが、何が問題なのかわかりません。私は学生と保護者の間に関係があり、学生には多くの保護者がいて、保護者は学生に属しています

学生フォームに挿入された入学番号が保護者フォームに取得できません。関係ないようですが、解決できません。

ユーザーが私の質問に反対票を投じる理由がわかりません!:D 私はこれを機能させることができないので、助けを求めました:O

students_controller.rb

class StudentsController < 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

Guardians_controller.rb

class GuardiansController < ApplicationController
  def index
  end

  def show
  end

  def new
    @guardian = Guardian.new
  end

  def edit
  end
end

学生.rb

class Student < 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

ガーディアン.rb

class Guardian < 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

ガーディアン/new.html.erb

<h1>Admission</h1>
<h4>Step 2 - Parent details</h4>

<div class="row-fluid">
  <div class="span4 offset1 hero-unit">
    <%= form_for @guardian do |f| %>
        <% if @guardian.errors.any? %>
            <div id="error_explanation">
              <div class="alert alert-error">
                The form contains <%= pluralize(@guardian.errors.count, 'error') %>
              </div>
              <ul>
                <% @guardian.errors.full_messages.each do |msg| %>
                    <li>* <%= msg %></li>
                <% end %>
              </ul>
            </div>
        <% end %>

        <fieldset>
        <div class="field">
          <%= f.label 'Student Admission number' %>
          <%= f.text_field @guardian.student.admission_no %>
        </div>
4

2 に答える 2