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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:14:42+00:00 2026-05-25T12:14:42+00:00

I have a controller where I’m doing some kind of funky selection. I have

  • 0

I have a controller where I’m doing some kind of funky selection. I have an Invitation table that belongs_to a User, and has_one User.

When destroying an invitation, I want the “has_one User” to be be doing the destroying, is in my controller I’m first getting an array of invitations the User has been invited on with:

def destroy
    @invitations = Invitation.find_by_recipient_email(current_user.email)

From this @invitations array, I want to do a find using the :id parameter. Is there a way to do something like this:

@invitations = Invitation.find_by_recipient_email(current_user.email)
    @invitation = @invitations.find(params[:id])

That way I can limit the invitations the user can access only to the ones they’ve been invited on (with the current_user method) and then select the specific invitation. I currently can’t do this as .find does not work on an array.

Thanks for the help/pointers.

edit: sorry I made the post kind of confusing, here’s some more info:

Here’s my entire destroy method right now, I only want to delete one record:

def destroy
    @invitations = Invitation.find_by_recipient_email(current_user.email)
    @invitation = @invitations.find(params[:id])  

    if @invitation.destroy
      redirect_to invitations_path, :notice => "Declined invitation"
    else
      redirect_to :back
    end
  end

My Invitation object looks like:

Invitation(id: integer, list_id: integer, sender_id: integer, recipient_email: string, created_at: datetime, updated_at: datetime) 

Where send_id and recipient_email are two different users.

My invitation.rb:

belongs_to :sender, :class_name => 'User'
  has_one :recipient, :class_name => 'User'

Maybe the issue is I would be calling something like current_users.invitations.find(params[:id]) and redo my invitation model?

  • 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-25T12:14:43+00:00Added an answer on May 25, 2026 at 12:14 pm

    You can just do this:

    invitatation_scope = Invitation.where(["recipient_email = ?",current_user.email])
    @invitation =  invitation_scope.find(params[:id])

    But you should use a before_filter:

    before_filter :load_user_invitation, :only=>[:edit,:update,:destroy]
    
    def load_user_invitation
      @invitation = Invitation.where(["recipient_email = ?",current_user.email]).find(params[:id])
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a controller action that checks this.User.Identity.IsAuthenticated What do you suggest how to
If user hits http://somewebsite/Cnt but i dont have controller with that name and i
I have a controller action that returns some JSON results to the jQuery Full
I have a controller that contains a tableView that spawns another controller modally to
I have controller method in my MVC application that I am calling using the
I have some controller logic: public function seafood() { $this->set('title', 'Seafood restaurants in and
In MVC/MVP style applications that have Controller/Presenter classes within the Client Application assembly and
I have controller that takes post parameters from HTML form, it will then send
I would like to have controller GET action that returns a JSON-serialized dictionary. The
I have standard servlet-mapping for Dispatcher Servlet - /app/* . I have controller that

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.