No default values in has_and_belongs_to_many generated checkboxes #891

Marmolin opened this Issue Oct 21, 2012 · 4 comments

2 participants


I have a has_and_belongs_to_many association between class Activity and training_objectives described in the table activities_training_objectives that I display by checkboxes by the following code

<%= semantic_form_for @activity, url: wizard_path, :html=>{:method=>'put'} do |form| %>
<%= form.input :training_objective_ids, :as => :check_boxes, :label=>'', :input_html =>{:title=> 'Ange aktivitetens namn'},:wrapper_html=>{:style=>'width:100%'},:collection=> {|objective| [put_training_objective(objective),]} %>

The values are displayed correctly but there are no pre-checked values although the activities_training_objectives table defines such values

Googling shows that this seems to be a problem for a long time, but I cannot find out the current status of formtastic?
Is this still a bug or a feature not implemented yet or maybe I am using formtastic in a invalid way. ?
Anyone that knows a work around ?

I use formtastic-2.2.1, Rails 3.2.0 and I also use the gem gem 'wicked' as the form is a kind of wizard form


This is a bit of a generic answer, but Formtastic should mark any checkboxes as checked if the current state of the model says they should be checked. That's what it's supposed to do, but doing this turns out to be non-trivial. I think part of the problem here may be that Formtastic is expecting you to use the association names for inputs (training_objectives, not training_objective_ids):

Try form.input :training_objectives ...


@Marmolin there's no "work-around", there's only "work it out". Can we see some more code? What did you try? What was the result? What sort of debugging did you do?

@justinfrench justinfrench reopened this Oct 31, 2012

Closing due to a lack of activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment