title: Associated models in Rails?
body: <p>In my rails application I have two models called Kases and Notes. They work in the same way comments do with blog posts, I.e. each Kase entry can have multiple notes attached to it.</p>
  
  <p>I have got everything working, but for some reason I cannot get the destroy link to work for the Notes. I think I am overlooking something that is different with associated models to standard models.</p>
  
  <p><strong>Notes Controller</strong></p>
  
  <pre><code>class NotesController &lt; ApplicationController  
    # POST /notes
    # POST /notes.xml
    def create
      @kase = Kase.find(params[:kase_id])
      @note = @kase.notes.create!(params[:note])
      respond_to do |format|
        format.html { redirect_to @kase }
        format.js
      end
    end
  
  end
  </code></pre>
  
  <p><strong>Kase Model</strong></p>
  
  <pre><code>class Kase &lt; ActiveRecord::Base
    validates_presence_of :jobno
    has_many :notes
  </code></pre>
  
  <p><strong>Note Model</strong></p>
  
  <pre><code>class Note &lt; ActiveRecord::Base
    belongs_to :kase
  end
  </code></pre>
  
  <p>In the Kase show view I call a partial within /notes called _notes.html.erb:</p>
  
  <p><strong>Kase Show View</strong></p>
  
  <pre><code>&lt;div id="notes"&gt;    
  
          &lt;h2&gt;Notes&lt;/h2&gt;
              &lt;%= render :partial =&gt; @kase.notes %&gt;
              &lt;% form_for [@kase, Note.new] do |f| %&gt;
                  &lt;p&gt;
                      &lt;h3&gt;Add a new note&lt;/h3&gt;
                      &lt;%= f.text_field :body %&gt;&lt;%= f.submit "Add Note" %&gt;
                  &lt;/p&gt;
              &lt;% end %&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p><strong>/notes/_note.html.erb</strong></p>
  
  <pre><code>&lt;% div_for note do %&gt;
  &lt;div id="sub-notes"&gt;
    &lt;p&gt;
    &lt;%= h(note.body) %&gt;&lt;br /&gt;
    &lt;span style="font-size:smaller"&gt;Created &lt;%= time_ago_in_words(note.created_at) %&gt; ago on &lt;%= note.created_at %&gt;&lt;/span&gt;
    &lt;/p&gt;
  
  &lt;%= link_to "Remove Note", kase_path(@kase), :confirm =&gt; 'Are you sure?', :method =&gt; :delete, :class =&gt; 'important' %&gt;
  
  &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>As you can see, I have a Remove Note destroy link, but that destroys the entire Kase the note is associated with. How do I make the destroy link remove only the note?</p>
  
  <pre><code>&lt;%= link_to "Remove Note", kase_path(@kase), :confirm =&gt; 'Are you sure?', :method =&gt; :delete, :class =&gt; 'important' %&gt;
  </code></pre>
  
  <p>Any help would, as always, be greatly appreciated!</p>
  
  <p>Thanks,</p>
  
  <p>Danny</p>