我有两个类;一个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
我真诚地感激任何&所有帮助我得到这一点。谢谢。
按你的*路线*表,我可以看到的路径'day_college_class',因此它应该是'day_college_class_path'。 –
@ArupRakshit这不是正确的答案。解决方案是修复'资源',如下所示。资源应始终是复数,而不是单数。 – meagar
@meagar Humm ..我可以看到,有人回答。我如何猜测,OP想要什么实际名称。这两种方式都是如此。如果OP正确地写*路由*,那么他可能会将路径输入为打字错误,,,或者你说的。 –