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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:39:55+00:00 2026-05-24T02:39:55+00:00

I have the following simple models: class Event < ActiveRecord::Base has_many :participations has_many :users,

  • 0

I have the following simple models:

class Event < ActiveRecord::Base
  has_many :participations
  has_many :users, :through => :participations
end

class Participation < ActiveRecord::Base
  belongs_to :event
  belongs_to :user
end

class User < ActiveRecord::Base
  has_many :participations
  has_many :events, :through => :participations
end

What I would like to do in my view is, dependant on the current users role, delete either an event and its participation record, or just a participation record on its own.

I currently have

<%= link_to ‘Delete event’, event, :confirm => ‘Are you sure?’,
:method => :delete %>

which deletes both event, and its participation. Do I need another action? or can hijack the destroy action of Event? What would it look like?

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-05-24T02:39:56+00:00Added an answer on May 24, 2026 at 2:39 am

    Well, a hack could be something like this, in a view helper:

    def link_to_delete_event( event, participation = nil )
      final_path = participation.nil? ? event_path( event ) : event_path( :id => event, :participation_id => participation )
      link_to 'Delete event', final_path, :confirm => 'Are you sure?', :method => :delete
    end
    

    And in your view you’d use link_to_delete_event( event ) to delete an event alone and link_to_delete_event( event, participation ) to delete the participation. Your controller could be something like this:

    def destroy
      @event = Event.find(params[:id])
      unless params[:participation_id].blank?
        @event.destroy
      else
        @event.participations.find( params[:participation_id] ).destroy
      end
      redirect_to somewhere_path
    end
    

    EDIT

    To make it less of a hack you should create a nested resource for participations under events:

    map.resources :events do |events|
      events.resources :participations
    end
    

    And then you’ll have to create a ParticipationsController, which could look like this:

    class ParticipationsController < ApplicationController
      before_filter :load_event
    
      def destroy
        @participation = @event.participations.find( params[:id] )
        @participation.destroy
        redirect_to( event_path( @event ) )
      end
    
      protected
    
      def load_event
        @event = Event.find( params[:event_id] )
      end
    end
    

    And the link_to helper would change to this:

    def link_to_delete_event( event, participation = nil )
      if participation
        link_to 'Remove participation', event_participation_path( event, participation ), :method => :delete
      else
        link_to 'Delete event', event_path( event ), :confirm => 'Are you sure?', :method => :delete
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following models to associate users with roles: class User < ActiveRecord::Base
I have models similar to the following: class Band(models.Model): name = models.CharField(unique=True) class Event(models.Model):
I have following simple class: @interface Article: NSObject { NSString *title; } @property (copy,
I have the following simple Java code: package testj; import java.util.*; public class Query<T>
i have the following simple script <input class=input type=text name=password style=color: #797272; value= <?php
imagine the following simple Models (example for simplicity reasons; in fact, we have MVVM
I have the following django model (mapped to table 'A'): class A(models.Model): name =
I have the following models: class Territory(models.Model): name = models.CharField(max_length=30) power = models.ForeignKey(Power, null=True,
In a django application I have the following model: class Appointment(models.Model): #some other fields
Take the following simple object model for example: class Course has_many :enrollments has_many :students,

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.