Re: Routing acts_as_commentable form_for submission

Neil Cauldwell
2008-03-18T09:23:00Z

Adam Cohen wrote:
> you could create a CommentsController and use hidden form fields in a
> shared
> view to tell the comments controller which type of object the comment
> should
> be associated with.
> For example:
>
> app/views/shared/_comments.rhtml
>
> <% item = comments %>
>
> <% for comment in item.comments %>
> Comment posted by <%= comment.user.full_name %>
> <%= comment.body %>
> <% end %>
>
> Comment on this <%= item.class %>
> <% form_tag(comments_path) do -%>
>   <%= hidden_field_tag ''comment[commentable_id]'',
item.id %>
>   <%= hidden_field_tag ''comment[commentable_type]'',
item.class %>
>   <%= text_area_tag ''comment[body]'', nil, :style =>
''width:100%;
> height:100px;'' %>
>   <%= image_submit_tag (''post_comment_button.png'')
%>
> <% end %>
>
> The above would work with the polymorphic Comment class used by
> acts_as_commentable
>
> Adam
>
>
>
>
> On Mon, Mar 17, 2008 at 3:48 PM, Neil Cauldwell <

Thanks Adam, that''s pretty much what I was hoping I could do, i.e.
keeping a generic comments view which can handle object.comments, rather
than having to define news_item.comments, user.comments etc.

However, one thing has confused me;

<% item = comments %>

Why would I want to define item as the comments?