Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 863003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:14:16+00:00 2026-05-15T09:14:16+00:00

In my rails application I have two models called Kases and Notes. They work

  • 0

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.

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.

Notes Controller

class NotesController < 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

Kase Model

class Kase < ActiveRecord::Base
  validates_presence_of :jobno
  has_many :notes

Note Model

class Note < ActiveRecord::Base
  belongs_to :kase
end

In the Kase show view I call a partial within /notes called _notes.html.erb:

Kase Show View

<div id="notes">    

        <h2>Notes</h2>
            <%= render :partial => @kase.notes %>
            <% form_for [@kase, Note.new] do |f| %>
                <p>
                    <h3>Add a new note</h3>
                    <%= f.text_field :body %><%= f.submit "Add Note" %>
                </p>
            <% end %>
    </div>

/notes/_note.html.erb

<% div_for note do %>
<div id="sub-notes">
  <p>
  <%= h(note.body) %><br />
  <span style="font-size:smaller">Created <%= time_ago_in_words(note.created_at) %> ago on <%= note.created_at %></span>
  </p>

<%= link_to "Remove Note", kase_path(@kase), :confirm => 'Are you sure?', :method => :delete, :class => 'important' %>

</div>
<% end %>

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?

<%= link_to "Remove Note", kase_path(@kase), :confirm => 'Are you sure?', :method => :delete, :class => 'important' %>

Any help would, as always, be greatly appreciated!

Thanks,

Danny

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:14:16+00:00Added an answer on May 15, 2026 at 9:14 am
    <%= link_to "Remove Note", note_path(note), :confirm => 'Are you sure?', :method => :delete, :class => 'important' %>
    

    you also will need the following entry in config/routes.rb (check if it already exists)

    map.resources :notes
    

    and check for following method in your NotesController

    def destroy
      @note = Note.find(params[:id])
      @note.destroy
      .... # some other code here
    end 
    

    there’s also another way of doing that if you don’t have a NotesController and don’t want to have it

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two models/tables in my Rails application: discussions and comments. Each discussion has_many
In rails application I have two models: Food and Drink . Both food and
In my Rails application, I have two models, Articles and Projects, which are both
I am creating a site in Ruby on Rails, I have two models a
I have two databases in use in a Ruby on Rails application; one is
I am working on a rails application (I have some experience with rails). But,
I've got a rails application where users have to log in. Therefore in order
I'm looking at building a Rails application which will have some pretty large tables
I have a rails application where each user has a separate database. (taking Joel
I have a rails application which is still showing the cachebusting numeric string at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.