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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:57:29+00:00 2026-06-04T11:57:29+00:00

I have project model that has many tasks. Both project and tasks can have

  • 0

I have project model that has many tasks. Both project and tasks can have many discussions, and therefore I made Discussions polymorphic model(see below).

I wish to be able to click the link and mark ‘discussion’ as finished.

The way I went on to do it is to make a custom action in the ‘discussion controller’ that changes the boolean value of the ‘finished’ attribute from false to true. How to make that link_to helper in the discussion show page succesfully route to that custom action in the discussions controller? Also, is this the best practice to do this?

Discussion model

  1 class Discussion < ActiveRecord::Base  
  4   belongs_to :user
  5   belongs_to :discussionable, :polymorphic => true 
 28 end

Project model

  1 class Project < ActiveRecord::Base 
  7   has_many :tasks, :dependent => :destroy
  8   has_many :discussions, :as => :discussionable, :dependent => :destroy
 24 end 

Task model

  1 class Task < ActiveRecord::Base          
  7   belongs_to :project      
 14   has_many :discussions, :as => :discussionable, :dependent => :destroy
 27 end

So far my link_to helper looks like below, but it doesnt work(doesnt strike the custom ‘finish’ action as I want)…

Discussion show

7   <%= link_to 'Finish discussion', polymorphic_path([@parent, @discussion]), :action => 'finish' %>

This is this custom finish action in discussion controller.(I have before_filter that defines this @discussion variable from params[:id])

 33   def finish
 34     if @discussion.update_attribute(:finished, true)
 35       flash[:notice] = "it worked"    
 36       else
 37       flash[:alert] = 'You must be an admin to do that'
 38     end
 39   end

I also haven’t fiddled with routes.rb, as I don’t know if I have to.

Routes.rb

  1 PrjctMngr::Application.routes.draw do                 
 13     
 14   # PROJECTS
 15   resources :projects do
 16     resources :tasks
 17     resources :discussions
 18   end
 19 
 20   # TASKS
 21   resources :tasks do
 22     resources :subtasks
 23     resources :discussions
 24   end
 31 
 32   # DISCUSSIONS
 33   resources :discussions do
 34     resources :comments    
 35   end
 36 
 37 end
  • 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-04T11:57:30+00:00Added an answer on June 4, 2026 at 11:57 am
     <%= link_to 'Finish discussion', polymorphic_path([@parent, @discussion], :action => 'finish'), :method => :put %>
    

    action option is for the path helper, not tag helper 😉

    all assuming you have route set up propery
    #routes.rb
    resources :tasks do 
      resources :discussions do
        put :finish, :on => :member
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a Rails 3.2 app I have a model Project, which has many Tasks.
I have a projects resource that has many tasks. I want to ensure that
Lets say we have a Company model, that has many Employees And has many
In my project I have a Forum that has many Topics, and each Topic
I have a rails project where project model has many issues. class Project <
I have a project model that has_many :tasks . I added a nested resource
I have a Java project that I'm trying to implement with a model-view-controller design.
I have a Project model and it has some text attributes, one is summary.
Say I have Project , that is in many-to-many association with Tag . I'm
I have a User model that has_many projects. The Project model belongs_to the User

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.