Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Commit

Permalink
Fix radios is nil
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorenzo Rivosecchi committed May 16, 2019
1 parent 70ff362 commit 09a5075
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/generators/binda/setup/setup_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,19 @@ def setup_maintenance_mode
puts "2) Setting up maintenance mode"

# Use radio field_type untill truefalse isn't available
unless FieldSetting.find_by(slug: 'maintenance-mode').present?
if FieldSetting.find_by(slug: 'maintenance-mode').nil?
maintenance_mode = @field_settings.create!( name: 'Maintenance Mode', field_type: 'radio', position: 1, allow_null: false, slug: 'maintenance-mode' )
# create active and disabled choices
disabled = maintenance_mode.choices.create!( label: 'disabled', value: 'false' )
maintenance_mode.choices.create!( label: 'active', value: 'true' )

# Create field settings for dashboard
instance_field_settings = FieldSetting
.includes(field_group: [ :structure ]).where(binda_structures: { id: @dashboard.structure.id })
instance_field_settings.each do |field_setting|
field_setting.create_field_instance_for( @dashboard )
end

# assign disabled choice and remove the temporary choice
@dashboard.reload
@dashboard.radios.first.choices << disabled
Expand Down

0 comments on commit 09a5075

Please sign in to comment.