views:

168

answers:

1

Given

As the User, I am at a nested new vendors/5/reviews/new. In addition to :params that will get written to the Review model, I need to be able to include tags that belong to the Vendor model.

I have used acts_as_taggable_on (http://github.com/mbleigh/acts-as-taggable-on):

class Vendor....
     acts_as_taggable_on :tags, :competitors

I use formtastic to submit the tags and field_for to make sure that I write to vendor even though the form is on a CREATE Review:

 semantic_form_for ....

 <% fields_for :vendor do |vendor| %>
      <p>
        &lt;%= vendor.label :tags %&gt;<br />
        &lt;%= vendor.text_field :tag_list %&gt;
      </p>
 &lt;% end %&gt;

I try to display the tags for the Vendor with the following:

Tags:  <%=h @vendor.tag_list %>

My outcome: NOTHING.

1) Am I correctly writing the tags? It looks like it is create the right SQL in the console

2) Am I doing the right approach to display the tag list using acts_as_taggable_on?

A: 

First, I'm a bit confused why you're using Formtastic (semantic_form_for) when all of the helpers in the form are standard rails helpers (fields_for, label, text_field), so this really doesn't have much to do with Formtastic.

Second, if the form is for a Vendor record (form_for(@vendor)), then fields_for(:vendor) doesn't make any sense. Using fields_for inside a form_for creates a nested form with nested attributes (useful to create a parent record and an associated record at the same time).

I'd need to see a complete sample of the form code to really get a grip on what you're trying to do, but I think you've over complicated something quite simple. Either way, my advice is to correctly understand form_for before using semantic_form_for.

Justin French
Hi, changed the fields in my environmet to formtastic helps...sorry, didn't post. let me post the entire form, I think what I want to do is not to nest, but to post to two models....the form is to post to reviews...hmmm...I wonder if I can post review.vendor.tags (the vendor object is what's acts_as_taggable.....
Angela