app/controllers/binda/field_groups_controller.rb in binda-0.1.0 vs app/controllers/binda/field_groups_controller.rb in binda-0.1.1
- old
+ new
@@ -33,11 +33,10 @@
def update
# Add nested classes
add_new_field_settings
add_new_choices
-
update_choices
# Update the other ones
if @field_group.update(field_group_params)
reset_field_settings_cache
@@ -143,16 +142,21 @@
def add_new_choices
# Create new fields if any
unless new_params[:new_choices].nil?
new_params[:new_choices].each do |choice|
unless choice[:label].blank? || choice[:value].blank?
- new_choice = Choice.create( choice )
- unless new_choice
- return redirect_to edit_structure_field_group_path( @structure.slug, @field_group.slug ), flash: { error: new_choice.errors }
- end
+ create_new_choice choice
end
end
end
+ end
+
+ # Create new choice (depends directly from add_new_choice method)
+ def create_new_choice choice
+ new_choice = Choice.create( choice )
+ unless new_choice
+ return redirect_to edit_structure_field_group_path( @structure.slug, @field_group.slug ), flash: { error: new_choice.errors }
+ end
end
def update_choices
return if field_group_params[:field_settings_attributes].nil?
field_group_params[:field_settings_attributes].each do |_, field_setting_params|