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 7978027
In Process

The Archive Base Latest Questions

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

I have a users model that can have many holidays through a rich join

  • 0

I have a users model that can have many holidays through a rich join table.. My destroy statement on my view is deleting from the holidays table and NOT the user_holidays table as it should.. see below:

class HolidaysController < ApplicationController
  def destroy 
  @user = User.find(params[:user_id]) 
  @user_holiday = @user.holidays.find(params[:id]) 
  @user_holiday.destroy 
  redirect_to @user 
  end
end

Heres the view button:

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

Models:

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

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

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

Any ideas? 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:22:40+00:00Added an answer on June 4, 2026 at 9:22 am

    You should use @user.user_holidays instead of @user.holidays

    @user_holiday = @user.user_holidays.where(holiday_id: params[:id])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Users model that can have many Groups through Memberships. If a
I have an Organization model that has_many users through affiliations. And, in the form
I have a event model that has many invitations. Invitations are setup through checkboxes
Is it ok to have only one model that can hold many different types
I have a table joining two models in a has many through relationship. Users
I have users that have many points and points belongs to users. Points can
I have a model called company that has_many users then users belongs_to company. class
I have a Django model that defines a TimeSlot. Each TimeSlot can hold a
I have a form I'm trying to set up ... Users can have many
Rails 3.0.3 ruby 1.9.2p0 The Problem: I have a Users table which has many

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.