Ruby on Railsは初めてです。コースとセクションの 2 つのモデルがあります。 コースモデル course.rb
class Course < ActiveRecord::Base
attr_accessible :course_name, :school_id
#associations
has_many :sections
end
section.rb
class Section < ActiveRecord::Base
attr_accessible :section_name, :school_id, :course_id
#associations
belongs_to :course
end
*sections_controller.rb*
def new
@section = Section.new
if params[:standard].present?
@course = Course.where(:school_id => params[:standard])
render :partial => "section"
end
end
*_form.html.erb*
<%= simple_form_for @section, :html => { :class => 'form-horizontal well' } do |f| %>
<div class="input string required"><label class="string required control-label" for="student_id"><abbr title="required">*</abbr> School Name</label><%= f.select :school_id, School.all.map { |i| [i.school_name, i.id]},:prompt => "--Select a Class--" %></div><br/>
<div id = "section_div">
</div>
<!-- Button to trigger modal -->
<a href="#myModal" role="button" class="btn btn-success" data-toggle="modal">Add Section</a>
<!-- Modal -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Section</h3>
</div>
<div class="modal-body">
<%= f.input :section_name %>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary">Save changes</button>
</div>
</div>
<div class="form-actions">
<%= f.button :submit, :class => 'btn-primary' %>
<%= link_to t('.cancel', :default => t("helpers.links.cancel")),
sections_path, :class => 'btn' %>
</div>
<% end %>
セクションでは、Model Course_id が nil として保存されています。これを解決するには?私を助けてください。