I'm working on this application where the user can add new notes to a
specific article. I want to display the last note on the add new notes
page for that article.
I have a problem that if you try to visit the add a new note page for
an article that doesn't have any notes, it will give you an error
saying the first column of the notes table is nil - if I swap around
the sql it would change the error to cannot find id. I've tried so
many things but none of it work and I really would appreciate any
help.
Basically if their is a note for an article I want it to show up above
the form to add new notes to an article - if their isn't any notes for
that article then just show the form.
Then in the controller (assuming you have an article in @article):
@note = @article.notes.find(:first, :order => "created_at DESC")
will give you the latest added note (if any)
in the view:
<% if @note then %>
... show the note...
<% end %>