Ruby on rails 如何将值传递给自定义外键并使外键以第二种形式显示其值
如何将值传递给自定义外键(沃德_id)以及如何制作将插入学生表格的入学编号,出现在第二张表格“家长/监护人详细信息>沃德_id”中,我有以下几点: 学生控制器.rbRuby on rails 如何将值传递给自定义外键并使外键以第二种形式显示其值,ruby-on-rails,ruby-on-rails-3,model,form-for,Ruby On Rails,Ruby On Rails 3,Model,Form For,如何将值传递给自定义外键(沃德_id)以及如何制作将插入学生表格的入学编号,出现在第二张表格“家长/监护人详细信息>沃德_id”中,我有以下几点: 学生控制器.rb class StudentsController < ApplicationController def index @student = Student.all end def show @student = Student.find(params[:id]) end def new
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
class GuardiansController < ApplicationController
def index
end
def show
end
def new
@guardian = Guardian.new
end
def edit
end
end
学生/new.html.erb
<h1>Admission</h1>
<h4>Step 1 - Student details</h4>
<div>
<div class="span6 offset2">
<%= form_for(@student) do |f| %>
<% if @student.errors.any? %>
<div id="error_explanation">
<div class="alert alert-error">
The form contains <%= pluralize(@student.errors.count, 'error') %>
</div>
<ul>
<% @student.errors.full_messages.each do |msg| %>
<li>* <%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<table border="0" style="width: 65%" class='hero-unit'>
<tr>
<th><div class="field"><%= f.label :admission_no %></div></th>
<th><div class="field"><%= f.text_field :admission_no %></div></th>
</tr>
<tr>
<th><div class="field"><%= f.label :admission_date %></div></th>
<th><div class="field"><%= f.text_field :admission_date , :class => 'datepicker'%></div></th>
</tr></table>
<h4>Student - Personal Details</h4>
<table border="0" style="width: 65%" class='hero-unit'>
<tr>
<th><div class="field"><%= f.label :first_name %></div></th>
<th><div class="field"><%= f.text_field :first_name %></div></th>
</tr>
<tr>
<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 :ward_id , disabled: true %>
</div>
<h4>Parent - Personal Details</h4>
<div class="field">
<%= f.label :first_name %>
<%= f.text_field :first_name %>
</div>
//not the whole file, just copied what is needed to be seen
入场券
第1步-学生详细信息
表格包含
- *
'日期选择器''>
学生-个人资料
监护人/new.html.erb
<h1>Admission</h1>
<h4>Step 1 - Student details</h4>
<div>
<div class="span6 offset2">
<%= form_for(@student) do |f| %>
<% if @student.errors.any? %>
<div id="error_explanation">
<div class="alert alert-error">
The form contains <%= pluralize(@student.errors.count, 'error') %>
</div>
<ul>
<% @student.errors.full_messages.each do |msg| %>
<li>* <%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<table border="0" style="width: 65%" class='hero-unit'>
<tr>
<th><div class="field"><%= f.label :admission_no %></div></th>
<th><div class="field"><%= f.text_field :admission_no %></div></th>
</tr>
<tr>
<th><div class="field"><%= f.label :admission_date %></div></th>
<th><div class="field"><%= f.text_field :admission_date , :class => 'datepicker'%></div></th>
</tr></table>
<h4>Student - Personal Details</h4>
<table border="0" style="width: 65%" class='hero-unit'>
<tr>
<th><div class="field"><%= f.label :first_name %></div></th>
<th><div class="field"><%= f.text_field :first_name %></div></th>
</tr>
<tr>
<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 :ward_id , disabled: true %>
</div>
<h4>Parent - Personal Details</h4>
<div class="field">
<%= f.label :first_name %>
<%= f.text_field :first_name %>
</div>
//not the whole file, just copied what is needed to be seen
入场券
步骤2-父级详细信息
表格包含
- *
家长-个人资料
//不是整个文件,只是复制了需要查看的内容
<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 :ward_id , disabled: true %>
</div>
<h4>Parent - Personal Details</h4>
<div class="field">
<%= f.label :first_name %>
<%= f.text_field :first_name %>
</div>
//not the whole file, just copied what is needed to be seen