Warn users if Simple Form is not configured in the application
This commit is contained in:
parent
762386912a
commit
1f41dd3b7d
|
@ -36,6 +36,12 @@ to
|
|||
See https://github.com/plataformatec/simple_form/pull/997 for more information.
|
||||
WARN
|
||||
|
||||
@@configured = false
|
||||
|
||||
def self.configured? #:nodoc:
|
||||
@@configured
|
||||
end
|
||||
|
||||
## CONFIGURATION OPTIONS
|
||||
|
||||
# Method used to tidy up errors.
|
||||
|
@ -235,6 +241,7 @@ See https://github.com/plataformatec/simple_form/pull/997 for more information.
|
|||
# Default way to setup SimpleForm. Run rails generate simple_form:install
|
||||
# to create a fresh initializer with all configuration values.
|
||||
def self.setup
|
||||
@@configured = true
|
||||
yield self
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,5 +3,12 @@ require 'rails/railtie'
|
|||
module SimpleForm
|
||||
class Railtie < Rails::Railtie
|
||||
config.eager_load_namespaces << SimpleForm
|
||||
|
||||
config.after_initialize do
|
||||
unless SimpleForm.configured?
|
||||
warn '[Simple Form] Simple Form is not configured in the application and will use the default values.' +
|
||||
' Use `rails generate simple_form:install` to generate the Simple Form configuration.'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,4 +6,12 @@ class SimpleFormTest < ActiveSupport::TestCase
|
|||
assert_equal SimpleForm, config
|
||||
end
|
||||
end
|
||||
|
||||
test 'setup block configure Simple Form' do
|
||||
SimpleForm.setup do |config|
|
||||
assert_equal SimpleForm, config
|
||||
end
|
||||
|
||||
assert_equal true, SimpleForm.configured?
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue