与课程和课程实例有关联。当我访问url / courses / 1 / course_instances / new时,我收到以下错误。
这是我得到的错误:
No route matches {:controller=>"course_instances", :course_id=>nil}
模型
课程:
class Course < ActiveRecord::Base
attr_accessible :code, :credits, :description, :hours, :id, :name, :pass_mark
has_many :course_instances, :dependent => :destroy
accepts_nested_attributes_for :course_instances
end
课程实例
class CourseInstance < ActiveRecord::Base
attr_accessible :end_date, :id, :start_date
belongs_to :course
end
路线
Sis::Application.routes.draw do
resources :courses do
resources :course_instances
end
root :to => 'home#index'
end
课程实例控制器
class CourseInstancesController < ApplicationController
before_filter :find_course
def new
@course_instance = @course.course_instances.build
respond_to do |format|
format.html
end
end
def find_course
@course = Course.find(params[:course_id])
end
end
new.html.erb
<%= form_for ([@course, @course_instance]) do |f| %>
---- excluded for brevity ----
Rake Routes
new_course_course_instance GET /courses/:course_id/course_instances/new(.:format) course_instances#new
答案 0 :(得分:0)
我不确定我做了什么,但它开始起作用了。我尝试回溯以重新创建错误但是到目前为止我没有成功。奇怪的!感谢大家的帮助!