I've got two classes; a Day class and a CollegeClass class. The day is made up of many college classes and the day is created before a college class. The error im getting
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'
Here is my Day model
class Day
include Mongoid::Document
field :user, type: String
field :date, type: String
embeds_many :college_class
accepts_nested_attributes_for :college_class
end
My College Class model
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
A college class is created on the show page for a Day. Here is the form for the creation of a college class:
<%= 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 %>
There is currently nothing in the show method in the day controller. These are the controller actions for the creation of a new College Class
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
The routes for the two models:
resources :days do
resources :college_class
end
Which gives us these:
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
I genuinely appreciate any & all help I get with this. Thanks.
day_college_class, thus it should beday_college_class_path.resources, as below. Resources should always be plural, not singular.day_college_class_pathas you suggest. Rails is generating that name based on the name of his model.