Permalink
Browse files

Fixed multiselect bug. Also, autodeserialize arrays

  • Loading branch information...
1 parent c580a58 commit 0db6599c56dec3f54647fb899db55fb11c9dbc9f @lapluviosilla lapluviosilla committed Sep 29, 2013
@@ -3,6 +3,7 @@ class ProjectsSetupController < ApplicationController
steps :about_you, :the_project, :location, :content, :agreement, :confirmation
before_filter :check_step
+ before_filter :clean_select_multiple_params
def show
@project = current_project
@@ -31,4 +32,13 @@ def current_project
def check_step
# TODO: Add a validation to make sure user isn't skipping ahead
end
+
+ def clean_select_multiple_params hash = params
+ hash.each do |k, v|
+ case v
+ when Array then v.reject!(&:blank?)
+ when Hash then clean_select_multiple_params(v)
+ end
+ end
+ end
end
View
@@ -33,6 +33,12 @@ class Project < ActiveRecord::Base
%w(required_languages related_student_passions related_fields_of_study student_educational_requirement).each do |f|
# serialize f.to_sym, Array
enumerize f, in: I18n.t("enumerize.project." + f), multiple: true
+
+ define_method "#{f}_with_deserialize" do
+ value = send("#{f}_without_deserialize")
+ value = JSON.parse(send("#{f}_without_deserialize")) if value && value.is_a?(String)
+ end
+ alias_method_chain f, :deserialize
end
# TODO: Partial validations with wizard steps
@@ -34,6 +34,6 @@
%fieldset
= f.fields_for :field_host do |f_field_host|
= f_field_host.input :role_title
- = f_field_host.input :years_associated_with_organization, as: :integer
+ = f_field_host.input :years_associated_with_organization
= f.submit "Save & Continue to Step #2", class: "button button-orange"
@@ -11,8 +11,8 @@
= f.input :team_mode, as: :boolean, label: false, input_html: {style:"display:none;"}
-# = f.input :min_stay_duration
- = f.input :min_students, label: 'Min. number of students to make this project worthwhile?', as: :integer
- = f.input :max_students, label: 'Max. number of students you can house at any one time?', as: :integer
+ = f.input :min_students, label: 'Min. number of students to make this project worthwhile?'
+ = f.input :max_students, label: 'Max. number of students you can house at any one time?'
%h3.center Project Sessions
@@ -35,7 +35,7 @@ en:
- Creative Writing
- Cultural Anthropology
- Education & Teaching
- - Engineering: Elec, Chem, Mech
+ - "Engineering: Elec, Chem, Mech"
- English
- Environmental Studies
- Fine Art

0 comments on commit 0db6599

Please sign in to comment.