请我需要帮助!似乎我的关联无法正常工作,但我找不到问题所在。我有学生和监护人的关系,学生有很多监护人,监护人属于学生
学生表和监护人表中插入的录取号码无法获取,似乎没有关系,但我无法解决!
我不知道为什么用户对我的问题投反对票!:D 我只是无法完成这项工作,所以我寻求帮助 :O
student_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
监护人控制器.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>