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

  • SEARCH
  • Home
  • 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 7977801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:18:47+00:00 2026-06-04T09:18:47+00:00

Im trying to add a destroy button on my nested resource and getting this

  • 0

Im trying to add a destroy button on my nested resource and getting this error: No route matches [DELETE] "/users/1/2/4/5/holidays/7"

Heres the relevant parts of my view,routes, models, & controllers:

<% @user.holidays.each do |h| %>
  <td><%= h.name %></td>
  <td><%= h.date %></td>
  <td>
    <%= button_to('Destroy', user_holiday_path(@user.holidays), :method => 'delete', :class => 'btn btn-large btn-primary')  %>
  </td>
<% end %>

Routes

resources :users do
  resources :interests
  resources :holidays
end

Models

class User < ActiveRecord::Base
  has_many :holidays, :through => :user_holidays
end

class UserHoliday < ActiveRecord::Base
  attr_accessible :holiday_id, :user_id
  belongs_to :user
  belongs_to :holiday
end

class Holiday < ActiveRecord::Base
  attr_accessible :name, :date
  has_many :user_holidays
  has_many :users, :through => :user_holidays

end

Controller

class HolidaysController < ApplicationController
  def index
    @user_holidays = Holiday.find(params[:user_id])
    @holidays = @user_holidays.holidays
  end

  def new
  end

  def show
    @holiday = Holiday.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @holiday }
    end
  end

  def destroy
    @holiday = Holiday.find(params[:id])
    @holiday.destroy
  end
end

Thanks!!!

  • 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-06-04T09:18:49+00:00Added an answer on June 4, 2026 at 9:18 am

    Change this :
    <%= button_to('Destroy', user_holiday_path(@user.holidays), :method => 'delete', :class => 'btn btn-large btn-primary') %>
    to this:
    <%= button_to('Destroy', user_holiday_path(h), :method => 'delete', :class => 'btn btn-large btn-primary') %>

    Update

    Change your destroy action from :
    @holiday = Holiday.find(params[:id]) to
    @user_holiday = UserHoliday.find(params[:id])

    and in your view:
    change
    <% @user.holidays.each do |h| %>
    to

    <% @user.user_holidays.each do |h| %>

    Your associations need some correction and should be as follows:
    user has_many user_holidays
    user_holiday has_one holiday
    user_holidays belongs_to user

    You can access name and holiday via your h object:
    h.holiday.name
    h.holiday.date

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

Sidebar

Related Questions

I am trying to make a nested model form in which I can add/delete
I'm trying to make this button change background when you click it and this
I'm trying to add has_many_through relationship through a form nested in a parent model.
I'm trying to add some Hibernate functionality to a Spring web application. This is
I'm trying to add a fields_for attribute to a nested rails form. Any time
I am trying to add a button to a cell in my cellForRowAtIndexPath method.
I'm trying add data triggers to the default combobox style so each text item
I am trying add picture boxes dynamically. My code is as PictureBox picture =
Im new to asp.net mvc. I'm trying add new model class but it got
Trying to add init parameter names to a list in init(ServletConfig) method. public void

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.