title: Conforming Rails form into Formtastic Equivalent
body: <p>I have a Rails application where I am using Active Admin as the backend. Active Admin uses Formtastic and I am having trouble converting one of the input fields in my _form.html.erb for posts.</p>
  
  <p>Here is the form...</p>
  
  <pre><code>&lt;div class="container"&gt;
  &lt;%= form_for(@post) do |f| %&gt;
    &lt;% if @post.errors.any? %&gt;
      &lt;div id="error_explanation"&gt;
        &lt;h2&gt;&lt;%= pluralize(@post.errors.count, "error") %&gt; prohibited this post from being saved:&lt;/h2&gt;
        &lt;ul&gt;
        &lt;% @post.errors.full_messages.each do |msg| %&gt;
          &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt;
        &lt;% end %&gt;
        &lt;/ul&gt;
      &lt;/div&gt;
    &lt;% end %&gt;
  
    &lt;div class="field"&gt;
      &lt;%= f.label :title %&gt;&lt;br /&gt;
      &lt;%= f.text_field :title %&gt;
    &lt;/div&gt;
    &lt;div class="field"&gt;
      &lt;%= f.label :author %&gt;
      &lt;%= f.collection_select :blog_id, Blog.all, :id, :name, prompt: "Select a blog" %&gt;        
    &lt;/div&gt;
    &lt;div class="field"&gt;
      &lt;p&gt;
        Categories:&lt;br&gt;
        &lt;%= hidden_field_tag "post[category_ids][]", nil %&gt;
        &lt;% Category.all.each do |category| %&gt;
          &lt;%= check_box_tag "post[category_ids][]", category.id, @post.category_ids.include?(category.id), id: dom_id(category) %&gt; 
          &lt;%= label_tag dom_id(category), category.name %&gt;
        &lt;% end %&gt;    
      &lt;/p&gt;
    &lt;/div&gt;
    &lt;div class="field"&gt;
      &lt;%= f.hidden_field :status, value: "Draft" %&gt; 
    &lt;/div&gt;
    &lt;div class="field"&gt;
      &lt;%= f.label :body %&gt;&lt;br /&gt;
      &lt;%= f.text_area :body, class: "redactor", id: "redactor" %&gt;
    &lt;/div&gt;
    &lt;div class="field"&gt;
      &lt;%= f.label :published_on %&gt;&lt;br /&gt;
      &lt;%= f.date_select :published_on %&gt;
    &lt;/div&gt;
    &lt;div class="actions"&gt;
      &lt;%= f.submit %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Here is the portion that I am having trouble converting to formtastic specific code.  It comes from Ryan's screencast on <a href="http://railscasts.com/episodes/17-habtm-checkboxes-revised" rel="nofollow">HABTM Checkboxes</a>.</p>
  
  <pre><code>&lt;div class="field"&gt;
      &lt;p&gt;
        Categories:&lt;br&gt;
        &lt;%= hidden_field_tag "post[category_ids][]", nil %&gt;
        &lt;% Category.all.each do |category| %&gt;
          &lt;%= check_box_tag "post[category_ids][]", category.id, @post.category_ids.include?(category.id), id: dom_id(category) %&gt; 
          &lt;%= label_tag dom_id(category), category.name %&gt;
        &lt;% end %&gt;    
      &lt;/p&gt;
    &lt;/div&gt;
  </code></pre>
  
  <p>Here is the formcode that is in the admin/post.rb file for Active Admin.  If I use this I continue to get a no method error for category.  I know that the way it is currently listed is incorrect.</p>
  
  <pre><code>form do |f|
      f.inputs "Details" do
          f.input :blog, hint: "Select a blog"
          f.input :title, hint: "Enter blog post title"
          f.input :published_on, as: :date, include_blank: false, hint: "Select a date", :prompt =&gt; {:day =&gt; "Day", :month =&gt; "Month", :year =&gt; "Year"}, :start_year =&gt; Time.now.year
          f.input :status, as: :select, collection: ["Draft", "Published"], include_blank: false, hint: 'Select "Draft" to save and post later, and "Publish" to post now'
  
          f.input :categories, as: :check_boxes
  
          f.input :body, input_html: { class: "redactor", id: "redactor" }
      end
      f.buttons
  end
  </code></pre>
  
  <p>If anyone has any input I am most appreciated.  I have looked at the formtastic documentation and watched Ryan's screencasts, but am still having issues converting.</p>
  
  <p>Thanks!</p>
  
  <h2>EDIT: ABLE TO RESOLVE-SOLUTION BELOW</h2>
  
  <p>I was able to make this work after getting a little more familiar with Formtastic and Active Admin.  Below is the relevant code in the form, show, and index views in Active Admin.</p>
  
  <pre><code>ActiveAdmin.register Post do
  index do
      column "Post Title", :title
      column :blog
      column :published_on
      column :status
      column "Category", :categories do |post|
          post.categories.collect { |cat|  cat.name }.join(", ")
      end
      default_actions
  end 
  
  show do
      h5 "Created by #{post.blog.name} on #{post.created_at.strftime('%B %-d, %Y')}"
      h5 "Categories: #{post.categories.collect { |cat|  cat.name }.join(", ")}"
      h5 "Current Status: #{post.status}"
      h5 "Published On Date: #{post.published_on.strftime('%B %-d, %Y')} - (will only be posted if marked with Publish as status)"
      div do
          simple_format post.body
      end
  end
  
  form do |f|
      f.inputs "Details" do
          f.input :blog, hint: "Select a blog"
          f.input :title, hint: "Enter blog post title"
          f.input :published_on, as: :date, include_blank: false, hint: "Select a date", :prompt =&gt; {:day =&gt; "Day", :month =&gt; "Month", :year =&gt; "Year"}, :start_year =&gt; Time.now.year
          f.input :status, as: :select, collection: ["Draft", "Published"], include_blank: false, hint: 'Select "Draft" to save and post later, and "Publish" to post now'
          f.input :categories, as: :check_boxes, collection: Category.all
          f.input :body, input_html: { class: "redactor", id: "redactor" }
      end
      f.buttons
  end  
  end
  </code></pre>