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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:24:11+00:00 2026-06-04T23:24:11+00:00

I have Discussions (polymorphic) that belong to Projects, Tasks and Subtasks. Tasks belong to

  • 0

I have Discussions (polymorphic) that belong to Projects, Tasks and Subtasks. Tasks belong to Projects, and Subtasks to Tasks.

I have users connected to Projects via join table called ‘synapses’. Synapse model has user_id, project_id and boolean field called :leader which signals if the user has leader (AKA admin) rights.

For a user to close(finish) the discussion, he needs to be a leader of current project or needs to be the creator of that discussion. Here is the ‘finish’ method in Discussions controller:

 33   def finish
 34     if current_user.leader? || current_user.discussions.include?(@discussion)
 35       @discussion.update_attribute(:finished, true)
 36       redirect_to polymorphic_path([@parent, Discussion])
 37       flash[:notice] = "Discussion '#{@discussion.name}' finished"
 38     else
 39       flash[:alert] = 'You must be an admin to do that'
 40     end
 41   end

Since user model doesn’t have leader attribute on itself, I need to find the corresponding synapse between current user and project(which does have leader boolean field, showing if the user can close the discussion). Here is the method I have in application_controller to find the synapse:

  9   def find_synapse(user,project)  
 10     user.synapses.find_by_project_id(project)
 11   end

To find the synapse, I need to find the Project. So far I can find the parent of the Discussion, which can be either the Project, Task, or Subtask model.

The way I see it, I need to iterate through parents and than stop when the parent’s is of the class Project (for loop?). How to do this? Is this the best way to go about it? BTW, I tried using switch-case (when @parent.class is Task, do this, when class is Project, do that), but seems hackish and I didn’t manage it to work anyway.

  • 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-04T23:24:13+00:00Added an answer on June 4, 2026 at 11:24 pm

    If you define a method owning_product on project, task, subtask such that

    class Project
      def owning_project
        self
      end
    end
    
    class Task
      def owning_project
        project
      end
    end
    
    class Subtask
      def owning_project
        task.owning_project
      end
    end
    

    Then you can call owning_project on your discussion’s parent and get back the relevant project. In a way this is pretty much the same as your case statement but using the inheritance system to do the switching for you.

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

Sidebar

Related Questions

I have a polymorphic resource Discussion that can belong to either the Project, Task,
I have been trying to search answer for this, but all discussions that I
I would like to have a method called feed in my User model that
I have project model that has many tasks. Both project and tasks can have
There have been multiple discussions on this topic in the site but I am
I have looked on the web and the discussions/examples appear to be for traditional
I have read a great deal of discussions about javascript templating and Search Engine
I have problem like this https://dev.twitter.com/discussions/4563 if (webResponse.Headers[Content-Encoding] == gzip) { byte[] bytes =
I have a discussion board with the following table structure: +-------------------------------+ | TABLE: MESSAGES
I have a table which contains a column discussion_duration where I am storing certain

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.