diff --git a/app/helpers/admin/application_helper.rb b/app/helpers/admin/application_helper.rb deleted file mode 100644 index 8b9e633..0000000 --- a/app/helpers/admin/application_helper.rb +++ /dev/null @@ -1,35 +0,0 @@ -module Admin::ApplicationHelper - - def flash_class(level) - case level.intern - when :notice then "alert alert-info" - when :success then "alert alert-success" - when :error then "alert alert-danger" - when :alert then "alert alert-danger" - end - end - - def validation_state(model_instance, attribute) - if model_instance.errors.any? - if model_instance.errors[attribute].empty? - "has-success" - else - "has-error" - end - end - end - - def validation_state_feedback(model_instance, attribute) - if model_instance.errors.any? - if model_instance.errors[attribute].empty? - "glyphicon-ok" - else - "glyphicon-remove" - end - end - end - - def attribute_error_message(model_instance, attribute) - model_instance.errors[attribute].join('\n') - end -end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 0000000..77cc005 --- /dev/null +++ b/app/helpers/application_helper.rb @@ -0,0 +1,58 @@ +module ApplicationHelper + def flash_class(level) + case level.intern + when :notice then "alert alert-info" + when :success then "alert alert-success" + when :error then "alert alert-danger" + when :alert then "alert alert-danger" + end + end + + class ValidationFormBuilder < ActionView::Helpers::FormBuilder + def validation_text_field(attribute, label_text, options = { column_width: 10 }) + validation_inline_label(attribute, label_text, { column_width: 12 - options[:column_width] }) do + @template.text_field(@object_name, attribute, class: "form-control") + end + end + + def validation_inline_label(attribute, label_text, options = { column_width: 2 }, &block) + @template.content_tag(:div, class: "form-group form-group-lg has-feedback #{validation_state(@object, attribute)}") do + content = @template.label(@object_name, attribute, label_text, class: "col-sm-#{options[:column_width]} control-label") + content += @template.content_tag(:div, class: "col-sm-#{12 - options[:column_width]}") do + content = @template.capture(&block) + content += @template.content_tag(:span, "", class: "glyphicon #{validation_state_feedback(@object, attribute)} form-control-feedback") + content += @template.content_tag(:span, class: "help-block") do + attribute_error_message(@object, attribute) + end + content.html_safe + end + content.html_safe + end + end + + private + def validation_state(model_instance, attribute) + if model_instance.errors.any? + if model_instance.errors[attribute].empty? + "has-success" + else + "has-error" + end + end + end + + def validation_state_feedback(model_instance, attribute) + if model_instance.errors.any? + if model_instance.errors[attribute].empty? + "glyphicon-ok" + else + "glyphicon-remove" + end + end + end + + def attribute_error_message(model_instance, attribute) + model_instance.errors[attribute].join('\n') + end + end +end \ No newline at end of file diff --git a/app/views/admin/notices/_form.html.erb b/app/views/admin/notices/_form.html.erb index b565eb4..bab2f75 100644 --- a/app/views/admin/notices/_form.html.erb +++ b/app/views/admin/notices/_form.html.erb @@ -1,73 +1,31 @@ -
날짜 3일 전까지 공개 모집이 가능합니다
+ <%= f.validation_inline_label :to, "모집 인원", { column_width: 1 } do %> + <%= f.number_field :to, min: 1, class: "form-control" %> + <% end %> - - <%= attribute_error_message(@notice, :due_date) %> -날짜 3일 전까지 공개 모집이 가능합니다
+ <% end %>