Topic: Collection, partials and tag help?

Excuse me if I'm doubling up but hey-ho!

I'm a relative rails novice - I've produced a couple of sites but they're by no means complex - and I got stumped when trying to use a partial template to produce my HTML to manage, essentially the same set of tags (acts_as_tabable) applied to articles and content blocks throughout my site. So I intended to use the :collection business to pass the appropriate set of variables to the partial. Following so far? I'm not! tongue

So in my articles manager, I write such code:

<%= form_tag("/admin/article_tag/" + @article.path)%>
<%= render :partial => "tags", :collection => @article %>
<%= end_form_tag %>

and in my content manager I write the simerlar thing...

<%= form_tag("/admin/content_tag/" + @content.path)%>
<%= render :partial => "tags", :collection => @content %>
<%= end_form_tag %>

And my partial looks like so:

<table cellpadding = '5' cellspacing = '0' border = '0'>
        <th align = 'left'>Tags</th>
        <td><%= text_field_tag("tags", @tags.tags.collect{|tag|}.join(" "), :size => "30") %>&nbsp;<%= submit_tag "save" %></td>
        <td colspan = '2' class = 'subtext'>Space separated keywords</td>
        <td align = 'right' colspan = '2'>

Shocked that I was to see the error: "undefined method `each_with_index`"!

So I figure this is something acts_as_tagable generates without actually showing me, but I can't figure out where to go from here... some advice would be great!?



Last edited by paulus (2007-01-27 18:48:16)

Re: Collection, partials and tag help?

The ":collection" parameter expects an array passed to it, but it looks like you are just passing a single model. Perhaps you want the ":object" parameter?

<%= render :partial => "tags", :object => @article %>

This will make a local variable available to the partial with the same name as the partial (tags). It's not an instance variable (@tags).

Railscasts - Free Ruby on Rails Screencasts

Re: Collection, partials and tag help?

Thanks for your assistance, worked like a charm!