Problem
My app manages ProjElements
, which are subclassed into:
Milestone
Task
Decision
- ... etc
For a given ProjElement
's show.html.erb
, you can comment on that project element instance (e.g. you can add a comment on Milestone XYZ
or Decision ABC
). Like this:
// display project element specific stuff
// - e.g. show.html.erb for Milestone has milestone-specific stuff
// - e.g. show.html.erb for Decision has decision-specific stuff
// provide comment functionality
// - e.g. for Milestone's show.html.erb, code looks like
<%= form_for [@milestone, Comment.new] do |f| %>
<% if @milestone.comments.size > 0 %>
...
<% end %>
<% f.submit %>
<% end %>
Proposed approach
I plan to use a partial for the comment code and use it across the various
show.html.erb
views for different project elements, as per DRY. But ...How do I write generic code for the partial, the Rails way, so that the partial can deal with different project elements?