justinfrench/formtastic — Issue #806: Changing :as=>:check_boxes to :as=>:radio does not populate the radio button selections made previously for MTM relationship
Author: astockwell
Created: 2012-02-19 05:29:41+00:00
State: open

Hi there, somewhat new to Rails 3.x, and couldn't find an issue similar to this one (although a similar StackOverflow was asked [here] (http://stackoverflow.com/questions/5890889/default-not-getting-selected-in-formtastic-form)) -

I'm running through the RailsCast [formtastic vet application tutorials] (http://railscasts.com/episodes/185-formtastic-part-2), and have a form which populates checkboxes (**f.input :problems, :as => :check_boxes**) based on a many-to-many relationship:

**animal.rb:**

class Animal < ActiveRecord::Base
has_many :symptoms
has_many :problems, :through => :symptoms

**animals\_form.html.erb:**

<%= semantic_form_for @animal do |f| %>
<%= f.inputs do %>
<%= f.input :name, :hint => "Use the owner's name if none is provided" %>
<%= f.input :female, :as => :radio, :label => "Gender", :collection => [["Male", false], ["Female", true]] %>
<%= f.input :problems, :as => :check_boxes %>

<% end %>
<%= f.actions %>
<% end %>

This works flawlessly, but when I change it to **"f.input :problems, :as => :radio"**, it creates the radio inputs properly, and seems to save my selections properly upon database inspection, but when I return to edit an animal, my prior selection is not displayed (in fact no radio button is shown as selected). If I make a new selection, it will be saved, but if I make no selection, it retains my last saved choice. Not sure if I'm missing something with a :collection here, or where to go from here.