2014-06-06 64 views
0

我有兩個類;一個Day類和一個CollegeClass類。這一天是由許多大學課程組成的,而這一天是在大學課堂之前創建的。錯誤即時得到rails和mongoid形式的未定義方法路徑

ActionView::Template::Error (undefined method `day_college_classes_path' for#<#<Class:0xa0627dc>:0xa06bd3c>): 
26: <% end %> 
27: <% end %> 
28: 
29: <%= form_for [@day, CollegeClass.new] do |f| %> 
30: <%= f.text_field :module, placeholder: "Module" %> 
31: <br> 
32: <%= f.text_field :lecturer, placeholder: "Lecturer" %> 
app/views/days/show.html.erb:29:in `_app_views_days_show_html_erb___616937818__626026478' 

這裏是我的天模型

class Day 
    include Mongoid::Document 
    field :user, type: String 
    field :date, type: String 

    embeds_many :college_class 
    accepts_nested_attributes_for :college_class 
end 

我的大學課堂模式

class CollegeClass 
    include Mongoid::Document 

    field :module,  type: String 
    field :room,  type: String 
    field :lecturer, type: String 
    field :start_time, type: String 
    field :end_time, type: String 

    embedded_in :day 

    embeds_many :notes 
    embeds_many :tasks 

    accepts_nested_attributes_for :notes 
    accepts_nested_attributes_for :tasks 
end 

一個大專班是一天的節目頁面上創建。下面是創建大學課程的表格:

<%= form_for [@day, CollegeClass.new] do |f| %> 
<%= f.text_field :module, placeholder: "Module" %> 
<br> 
<%= f.text_field :lecturer, placeholder: "Lecturer" %> 
<br> 
<%= f.text_field :room, placeholder: "Room" %> 
<br> 
<%= f.text_field :start_time, placeholder: "Start Time" %> 
<br> 
<%= f.text_field :end_time, placeholder: "End Time" %> 
<br> 
<%= f.submit %> 
<% end %> 

當天控制器中沒有show方法。 這些都爲建立一個新的學院控制器動作類

def create 
    @day = Day.find(params[:id]) 
    @class = @day.college_class.create(class_params) 
    redirect_to @day 
    end 

    private 

    def class_params 
     params.require(:college_class).permit(:module, :lecturer, :room, :start_time, :end_time) 
    end 

的兩個車型路線:這讓我們這些

resources :days do 
    resources :college_class 
end 

day_college_class_index GET /days/:day_id/college_class(.:format)   college_class#index 
         POST /days/:day_id/college_class(.:format)   college_class#create 
    new_day_college_class GET /days/:day_id/college_class/new(.:format)  college_class#new 
    edit_day_college_class GET /days/:day_id/college_class/:id/edit(.:format) college_class#edit 
     day_college_class GET /days/:day_id/college_class/:id(.:format)  college_class#show 
         PATCH /days/:day_id/college_class/:id(.:format)  college_class#update 
         PUT /days/:day_id/college_class/:id(.:format)  college_class#update 
         DELETE /days/:day_id/college_class/:id(.:format)  college_class#destroy 
        days GET /days(.:format)        days#index 
         POST /days(.:format)        days#create 
       new_day GET /days/new(.:format)       days#new 
       edit_day GET /days/:id/edit(.:format)      days#edit 
        day GET /days/:id(.:format)       days#show 
         PATCH /days/:id(.:format)       days#update 
         PUT /days/:id(.:format)       days#update 
         DELETE /days/:id(.:format)       days#destroy 

我真誠地感激任何&所有幫助我得到這一點。謝謝。

+0

按你的*路線*表,我可以看到的路徑'day_college_class',因此它應該是'day_college_class_path'。 –

+1

@ArupRakshit這不是正確的答案。解決方案是修復'資源',如下所示。資源應始終是複數,而不是單數。 – meagar

+0

@meagar Humm ..我可以看到,有人回答。我如何猜測,OP想要什麼實際名稱。這兩種方式都是如此。如果OP正確地寫*路由*,那麼他可能會將路徑輸入爲打字錯誤,,,或者你說的。 –

回答

2

試着改變你的routes.rb這個

resources :days do 
    resources :college_classes 
end 
+1

非常感謝。 – ryan

+1

只是在那裏。不得不等待10分鐘。再次,非常感謝。 – ryan

相關問題