So i'm re-writing a form and using simple_form builders because this form 
has to be used in two contexts. The Values are saved correctly on Creation, 
but when i go to the edit view, the checkboxes are not being checked if the 
user has selected that option. 

The values that i'm having problems setting come from a field that's been 
serialized as an array. 


model 

class Pilgrim < ActiveRecord::Base 
    serialize :price, Array 
end

Using simple_form 

<%= f.collection_check_boxes :price, 
@trip.trip_type.type_fields.where(:variable => false), :id, :field_name %>

It's rendering the correct information, but on edit all the checkboxes are 
set to blank. 


The Way I was doing it previously

<% @fixed = @trip.trip_type.type_fields.where(:variable => false) %>
            <% @variable = @trip.trip_type.type_fields.where(:variable => 
true) %>
            <% @fixed.each do |field| %>
                <% @options = @trip.options %>
                <dl>
                  <% if @pilgrim.price %>
                      <%= check_box_tag "pilgrim[price][]",  field.id, 
 @pilgrim.price.include?(field.id.to_s) %>
                  <% else %>
                      <%= check_box_tag "pilgrim[price][]",  field.id %>
                  <% end %>
                  <em><%=field.field_name %></em> <%= 
number_to_currency(@options[field.id.to_s]) %>
                </dl>
            <% end %>


My problem with doing it the way i was is that i'm trying to use the same 
form when it's as a nested field in a .fields_for block and when i'm 
editing a single user. So i don't know know how i would build the 
"pilgrim[price][]" in the fields_for block. 





-- 
-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
--- 
You received this message because you are subscribed to the Google Groups "SD 
Ruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to