Module Mack::ViewHelpers::DataMapperHelpers
In: lib/mack-data_mapper/helpers/orm_helpers.rb

Methods

Constants

DEFAULT_PARTIAL = %{ <div> <div class="errorExplanation" id="errorExplanation"> <h2><%= pluralize_word(errors.size, "error") %> occured.</h2> <ul> <% for error in errors %> <li><%= error %></li> <% end %> </ul> </div> </div> } unless Mack::ViewHelpers::DataMapperHelpers.const_defined?("DEFAULT_PARTIAL")

Public Instance methods

Provides view level support for printing out all the errors associated with the models you tell it. The DEFAULT_PARTIAL constant provides a simple, default, set of HTML for displaying the errors. If you wish to change this HTML there are two simple ways of doing it. First if you have a partial named: app/views/application/_error_messages.html.erb, then it will use that default, and not DEFAULT_PARTIAL. The other option is to pass in a path to partial as the second argument and that partial will be rendered.

[Source]

    # File lib/mack-data_mapper/helpers/orm_helpers.rb, line 25
25:       def error_messages_for(object_names = [], view_partial = nil)
26:         object_names = [object_names].flatten
27:         app_errors = []
28:         object_names.each do |name|
29:           object = instance_variable_get("@#{name}")
30:           if object
31:             if object.respond_to?(:errors)
32:               if object.errors.respond_to?(:full_messages)
33:                 app_errors << object.errors.full_messages.uniq
34:               end
35:             end
36:           end
37:         end
38:         app_errors.flatten!
39:         unless app_errors.empty?
40:           if view_partial.nil?
41:             if File.exist?(File.join(Mack.root, "app", "views", "application", "_error_messages.html.erb"))
42:               render(:partial, "application/error_messages", :locals => {:errors => app_errors})
43:             else
44:               render(:inline, DEFAULT_PARTIAL, :locals => {:errors => app_errors})
45:             end
46:           else
47:             render(:partial, view_partial, :locals => {:errors => app_errors})
48:           end
49:         else
50:           ""
51:         end
52:       end

Generates a password input tag for a given model and field

Example: model_password_field(@user, :password) # => <input id="user_username" name="user[username]" type="password" value="<@user.username‘s value>" />

[Source]

    # File lib/mack-data_mapper/helpers/orm_helpers.rb, line 67
67:       def model_password_field(model, property, options = {})
68:         model_text_field(model, property, {:type => :password}.merge(options))
69:       end

Generates a text input tag for a given model and field

Example: model_text_field(@user, :username) # => <input id="user_username" name="user[username]" type="text" value="<@user.username‘s value>" />

[Source]

    # File lib/mack-data_mapper/helpers/orm_helpers.rb, line 58
58:       def model_text_field(model, property, options = {})
59:         m_name = model.class.to_s.underscore
60:         non_content_tag(:input, {:type => :text, :name => "#{m_name}[#{property}]", :id => "#{m_name}_#{property}", :value => model.send(property)}.merge(options))
61:       end

[Source]

    # File lib/mack-data_mapper/helpers/orm_helpers.rb, line 71
71:       def model_textarea(model, property, options = {})
72:         m_name = model.class.to_s.underscore
73:         content_tag(:textarea, {:name => "#{m_name}[#{property}]", :id => "#{m_name}_#{property}", :cols => 60, :rows => 20}.merge(options), model.send(property))
74:       end

[Validate]