Inherited resources parent helpers - Rails

79 Views Asked by At

In the README for the inherited_resources gem it says the below associations allow the use of helpers such as parent #=> @task

class CommentsController < InheritedResources::Base
  belongs_to :project {
      belongs_to :file, :message, :task, :polymorphic => true
    }
end

What isn't explained is the helper itself. Do we know what this looks like, how it works? It would really help my understanding.

Cheers

1

There are 1 best solutions below

1
eeeeeean On

That gem looks like it's deprecated at this point, but:

What the README is saying is that projects can be a parent to a :file, :message, or :task. Furthermore any of those can be a parent to own :comment.

Where this could be useful, is you could call any of those helpers on the :comment to get information about its parent. For example you could write a conditional statement to deal with a :comment in different ways differently depending on whether it's parent object was a :file or a :task. Here's a random example:

render @comment unless @comment.parent_class == Task