2012-01-30 4 views
1

私は多くの関連するhas_and_belongsを持つレールアプリを持っています。私のレールアプリでこのエラーが発生しました:未定義のメソッド `course_users_path 'の#<#<クラス:0x10fd9be48>:0x10fd9d60>

/Users/Sam/makrrEdu/app/views/enroll/_form.html.erbを示す線#1が提起:

undefined method `course_users_path' for #<#<Class:0x10fd9be48>:0x10fd93d60> 

抽出されたソース(ライン#1の周りに)このコントローラのURL:

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> 

Tテンプレートインクルージョンのレース:アプリ/ビュー/入学/ 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' 

HERESに私のコード:


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 

新しいです.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 
+0

あなたはルートヘルパーにいくつか問題があります。未定義の 'course_users_path'メソッドはあなたのルートファイル内の何かを指しているはずです。 CourseUserモデルと関係があるものを投稿できますか? –

+1

"routes.rb"ファイルを投稿してください。おそらく 'resources:course_users'のようなエントリが欠落している可能性があります –

答えて

0

私はroutes.rbをファイルにresources :course_usersを入れるのを忘れていました。

関連する問題