Module: Showbuilder::ShowModelForm
- Included in:
- Showbuilder
- Defined in:
- lib/showbuilder/show_model_form.rb
Instance Method Summary collapse
- #model_error_messages(object) ⇒ Object
-
#show_model_form(models, options = {}, &block) ⇒ Object
show_model_form @customer do |form| form.show_text_input :name form.show_email_input :email form.show_password_input :password end.
Instance Method Details
#model_error_messages(object) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/showbuilder/show_model_form.rb', line 34 def (object) = object.errors..map do |key, value| value end .flatten! return if .empty? contents_tag(:div, :class => "alert alert-error") do |contents| contents << content_tag(:a, '×'.html_safe, :class=>'close' , "data-dismiss" => :alert) contents << content_tag(:strong, flash[:error], :class => "alert-heading") if flash[:error] contents << content_tag(:ul) do list_items = .map do |msg| content_tag(:li, msg) end list_items.join.html_safe end end end |
#show_model_form(models, options = {}, &block) ⇒ Object
show_model_form @customer do |form|
form.show_text_input :name
form.show_email_input :email
form.show_password_input :password
end
dependents: puts @customer.class.to_s.underscore # customer I18n.t(‘customer.name’) I18n.t(“customer.email’) I18n.t(‘customer.password’)
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/showbuilder/show_model_form.rb', line 19 def show_model_form(models, ={}, &block) models = Array.wrap(models) = || {} [:builder] = [:builder] || Showbuilder::Builders::ModelFormBuilder [:html] = [:html] || {} [:html][:class] = "#{[:html][:class]} form-horizontal" self.form_for(models, ) do |form| self.html_contents do |contents| contents << self.(models.last) contents << capture(form, &block) end end end |