У меня есть приложение rails с ассоциацией has_and_belongs ко многим, я получаю эту ошибку, когда перехожу к URL-адресу этого контроллера:
Отображение / Users / Sam / makrrEdu / app / views / enroll / _form.html.erb, где поднята строка # 1:
undefined method `course_users_path' for #<#<Class:0x10fd9be48>:0x10fd93d60>
Извлеченный источник (вокруг строки # 1):
1: <%= form_for(@userC) do |f| %>
2: <% if @userC.errors.any? %>
3: <div id="error_explanation">
4: <h2><%= pluralize(@userC.errors.count, "error") %> prohibited this enroll from being saved:</h2>
Трассировка включения шаблона: app / views / enroll / new.html.erb
Rails.root: /Users/Sam/makrrEdu
Application Trace | Framework Trace | Full Trace
app/views/enroll/_form.html.erb:1:in `_app_views_enroll__form_html_erb___794935172_2280224940'
app/views/enroll/new.html.erb:3:in `_app_views_enroll_new_html_erb___1934508758_2280307340'
app/controllers/enroll_controller.rb:24:in `new'
Вот мой код:
enroll_controller.rb
class EnrollController < ApplicationController
def new
@userC = CourseUser.new
respond_to do |format|
format.html # new.html.erb
format.json { render :json => @userC }
end
end
def index
end
def create
@userC = CourseUser.new(params[:course])
respond_to do |format|
if @userC.save
format.html { redirect_to @userC, :notice => 'Enroll was successfully created.' }
format.json { render :json => @userC, :status => :created, :location => @userC }
else
format.html { render :action => "new" }
format.json { render :json => @userC.errors, :status => :unprocessable_entity }
end
end
end
end
new.html.erb
<h1>New Enroll</h1>
<%= render 'form' %>
<%= link_to 'Back', courses_path %>
_form.html.erb
<%= form_for(@userC) do |f| %>
<% if @userC.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@userC.errors.count, "error") %> prohibited this enroll from being saved:</h2>
<ul>
<% @userC.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :description %><br />
<%= f.text_field :description %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
course_user.rb (модель)
class CourseUser < ActiveRecord::Base
belongs_to :user
belongs_to :course
attr_accessible :course_id, :user_id
end