From 7b7c992b7db63bb69388680033197ad993cddf23 Mon Sep 17 00:00:00 2001 From: yafeilee Date: Wed, 31 Dec 2014 01:02:31 +0800 Subject: [PATCH] add simple form configure --- config/initializers/simple_form.rb | 19 +++++++++++++ config/locales/simple_form.en.yml | 31 +++++++++++++++++++++ lib/templates/slim/scaffold/_form.html.slim | 10 +++++++ 3 files changed, 60 insertions(+) create mode 100644 config/initializers/simple_form.rb create mode 100644 config/locales/simple_form.en.yml create mode 100644 lib/templates/slim/scaffold/_form.html.slim diff --git a/config/initializers/simple_form.rb b/config/initializers/simple_form.rb new file mode 100644 index 0000000..72f2b8a --- /dev/null +++ b/config/initializers/simple_form.rb @@ -0,0 +1,19 @@ +# Use this setup block to configure all options available in SimpleForm. +SimpleForm.setup do |config| + config.wrappers :default, class: :input, + hint_class: :field_with_hint, error_class: :field_with_errors do |b| + b.use :html5 + b.use :placeholder + b.use :label_input + b.use :hint, wrap_with: { tag: :span, class: :hint } + b.use :error, wrap_with: { tag: :span, class: :error } + + end + + config.default_wrapper = :default + config.boolean_style = :nested + config.button_class = 'button' + config.error_notification_tag = :div + + config.error_notification_class = 'error_notification' +end diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml new file mode 100644 index 0000000..2374383 --- /dev/null +++ b/config/locales/simple_form.en.yml @@ -0,0 +1,31 @@ +en: + simple_form: + "yes": 'Yes' + "no": 'No' + required: + text: 'required' + mark: '*' + # You can uncomment the line below if you need to overwrite the whole required html. + # When using html, text and mark won't be used. + # html: '*' + error_notification: + default_message: "Please review the problems below:" + # Examples + # labels: + # defaults: + # password: 'Password' + # user: + # new: + # email: 'E-mail to sign in.' + # edit: + # email: 'E-mail.' + # hints: + # defaults: + # username: 'User name to sign in.' + # password: 'No special characters, please.' + # include_blanks: + # defaults: + # age: 'Rather not say' + # prompts: + # defaults: + # age: 'Select your age' diff --git a/lib/templates/slim/scaffold/_form.html.slim b/lib/templates/slim/scaffold/_form.html.slim new file mode 100644 index 0000000..a2ff775 --- /dev/null +++ b/lib/templates/slim/scaffold/_form.html.slim @@ -0,0 +1,10 @@ += simple_form_for(@<%= singular_table_name %>) do |f| + = f.error_notification + + .form-inputs +<%- attributes.each do |attribute| -%> + = f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %> +<%- end -%> + + .form-actions + = f.button :submit