Take the 2-minute tour ×

New to rails and getting confused on how to handle this. I am using rails 4. I am very stuck here and will try to talk through this problem.

I have a listings page which I am trying to add tags too. In my view (listings/new.html.erb) I have the following:


    <% if current_user.nil? %>
        <h2>You must be logged in to view this page </h2>
    <% else %>
        <%= form_for [@user, @listing] do |f| %>
      <%= f.label :title, 'Title' %> <br />
      <%= f.text_field :title %>

      <%= f.label :general_info, 'General Information' %> <br />
      <%= f.text_area :general_info %>

      <%= f.label :included, 'Included' %> <br />
      <%= f.text_field :included %>

       <%= f.label :length, 'Length' %> <br />
      <%= f.text_field :length %>

      <%= f.label :price, 'Price' %> <br />
      <%= f.text_field :price %>

      <% fields_for @tagging do |u| %>
        <%= u.label :tag, 'Tag' %> <br />
        <%= u.text_field :tag %>
      <% end %>

      <%= f.submit "submit" %>
    <% end %>

    <% end %>

The form works correctly for putting in the listing, but the tagging form options do not even appear to allow for content.

my listings_conroller #new looks like this:

  def new
    if (!current_user.nil?)
      @user = User.find(current_user.id)
      @listing = @user.listings.build
      @tagging = @listing.taggings.build


I want to be able to create a new listing with this form that also populates the database for the tags and I am very unsure on how to do this. I hope this is enough information, but if needed I have all the code here: https://bitbucket.org/r-s/ath/src . Very stuck on this any help would be appreciated.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Change it to:

<%= f.fields_for @tagging do |u| %>

Note the =.

share|improve this answer
thanks a ton.. one of those days, I should have caught that. –  r-s Jul 17 '13 at 1:52
add comment

You forgot to use builder:

  <%= f.fields_for @tagging do |u| %>
share|improve this answer
add comment

Your Answer


