0

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.

2
  • 1
    I think you're missing an 'end' at the end of your show method. Commented Jul 30, 2013 at 21:04
  • I definitely was, thanks for pointing that out. I'll add that in to the main comment. Commented Jul 30, 2013 at 21:20

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

0

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)

4 Comments

Thanks, I commented out that line but unfortunately I'm still faceing the error. Also, I'll add the line that raised the error in to the main post as well. Forgot to do that initially.
that's line 25 in what file? and could you include the output of $ rake routes also?
None of the routes have anything to do with notes - I feel like I've made some very basic error that's preventing them from showing up. Would you still like me to post the results if none of them deal with notes?
Do you have resources :notes in your routes.rb file?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.