Hi everyone, be forewarned that I’m new to ruby and rails.
I’ve got two models Course and Lesson. Course has_many :lessons and Lesson belongs_to :course. Currently the models themselves just have attr_accessible with the :name and :description fields.
When I try to load the form to create a new lesson (url is localhost:3000/courses/(course_id)/lessons/new), I get an error which says: undefined method `lessons_path’ and it points to line 1 of the form partial for making new lessons. I’ve tried searching on the net for a couple days now and have tried several different things, but I can’t figure it out.
Here’s the code:
lessons_controller.rb (relevant methods only)
- def new @course = Course.find(params[:course_id]) @lesson = @course.lessons.new end def create @course = Course.find(params[:course_id]) @lesson = @course.lessons.create(params[:lesson]) if @lesson.save redirect_to course_path(@course), :notice => “Successfully created lesson.” else render :action => ‘new’, :error => “Something went wrong.” end end*
_form.html.erb
- <%= form_for(@lesson) do |f| %> <%= f.error_messages %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.text_area :description %>
routes.rb
- resources :courses do member do get ‘detail’ end resources :lessons end*