Reputation: 1
I'm pretty new to Ruby on Rails so forgive me if this mistake is pretty amateur. I'm trying to create a section of a little website where people can take notes and have it record the author, the text, and the subject. When I try to access it on localhost, I get the following error:
line #25 raised:
undefined local variable or method `note_path' for #<#<Class:0x0000000be44598>:0x00000008648ce8>
25: <li><%= link_to 'Create Notes', note_path %></li>
Here's the code for the related files
new.html.erb:
1 <%= form_for :note, url: posts_path do |f| %>
2 <p>
3 <%= f.label :subject %><br>
4 <%= f.text_field :subject %>
5 </p>
6
7 <p>
8 <%= f.label :note %><br>
9 <%= f.text_area :note %>
10 </p>
11
12 <p>
13 <%= f.submit %>
14 </p>
15 <% end %>
show.html.erb:
1 <p>
2 <strong>Subject:</strong>
3 <%= @note.subject %>
4 </p>
5
6 <p>
7 <strong>Note:</strong>
8 <%= @post.note %>
9 </p>
notes_controller.rb:
1 class NotesController < ApplicationController
2 def new
3 end
4 def show
5 @note = Note.find(params[:id])
6 end
7 def create
8 @note = Note.new(params[:note].permit(:subject, :note))
9
10 @note.save
11 redirect_to @note
12 end
13 note GET /notes/:id(.:format) notes#show
14 private
15 def note_params
16 params.require(:note).permit(:subject, :note)
17 end
18 end
notes.rb:
1 class Notes < ActiveRecord::Base
2 attr_accessible :note, :subject
3 end
If anyone could help out, I'd appreciate it a lot. I feel like it's a very simple, beginner issue but I'm just unfamiliar with RoR and something seems to have slipped through the cracks.
Upvotes: 0
Views: 5370
Reputation: 3291
I don't think you actually included the section of code that is causing the problem, but based on the error you posted changing:
<li><%= link_to 'Create Notes', note_path %></li>
to this
<li><%= link_to 'Create Notes', new_note_path %></li>
should help solve your problem.
Also, make sure that
resources :notes
is in your routes.rb file
Upvotes: 3
Reputation: 10997
is line 12 in notes_controller.rb there or just a note? if so, delete it, or at least comment it out.
also, does your error point to a file and line number? if so can you add it and the relevant line(s)
Upvotes: 0