title: Comma separated array with a text_field in Rails
body: <p>I have some <strong>users</strong> that can have many <strong>posts</strong>, and each of those posts can have many <strong>tags</strong>. I've implemented that using a <strong>has_and_belongs_to_many</strong> relation between the posts and the tags.</p>
  
  <p>When creating a new post, the user can tag it using a comma separated list of values (much like when posting a new question on SO). If any of the tags does not exist already, it should be automatically created. This is the <strong>_fields.html.erb</strong> partial for the post:</p>
  
  <pre><code>&lt;%= form_for @post do |f| %&gt;
    &lt;%= render 'shared/error_messages', :object =&gt; f.object %&gt;
  
    &lt;h1 class="post"&gt;&lt;%= t(:new_post_message) %&gt;&lt;/h1&gt;
  
    &lt;div class="field"&gt;
      &lt;%= f.label t(:title) %&gt;
      &lt;br /&gt;
      &lt;%= f.text_field :title %&gt;
    &lt;/div&gt;
  
    &lt;div class="field"&gt;
      &lt;%= f.label t(:tag).pluralize %&gt;
      &lt;br /&gt;
      &lt;%= f.text_field :tags %&gt;
    &lt;/div&gt;
  
    &lt;div class="field"&gt;
      &lt;%= f.label t(:text) %&gt;
      &lt;br /&gt;
      &lt;%= f.text_area :content %&gt;
    &lt;/div&gt;
  
    &lt;div class="actions"&gt;
      &lt;%= f.submit t(:post_verb) %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Using <strong>f.text_field :tags</strong> right now results in an input element with <strong>[]</strong> for text.</p>
  
  <p>I don't use tags in <strong>posts_controller.rb</strong> yet, because I'm not sure how I should get and split the string value from the parameters:</p>
  
  <pre><code>def create
    @post = current_user.posts.build(params[:post])
    if @post.save
      redirect_to root_path
    else
      @stream = []
      render 'pages/home'
    end
  end
  </code></pre>
  
  <p>Has anyone tackled this problem before? Thanks a lot.</p>