Browse files

Fixed bug that was causing all activerecord attributes be saved as nil

Conflicts:

	lib/mail_form/shim.rb
  • Loading branch information...
1 parent 2dbfaa5 commit 9d6c57e785a77f8e5bb6a5acaa1d63d4e18bce39 @sporkd sporkd committed with nebirhos Sep 9, 2010
Showing with 14 additions and 10 deletions.
  1. +13 −1 lib/mail_form/delivery.rb
  2. +0 −8 lib/mail_form/shim.rb
  3. +1 −1 lib/mail_form/views/mail_form/contact.erb
View
14 lib/mail_form/delivery.rb
@@ -68,7 +68,10 @@ module ClassMethods
#
def attribute(*accessors)
options = accessors.extract_options!
- attr_accessor *(accessors - instance_methods.map(&:to_sym))
+
+ # TODO: make this not depend on column_names
+ columns_methods = self.respond_to?(:column_names) ? column_names.map(&:to_sym) : []
+ attr_accessor *(accessors - instance_methods.map(&:to_sym) - columns_methods)
if options[:attachment]
self.mail_attachments += accessors
@@ -147,5 +150,14 @@ def not_spam?
def deliver!
MailForm::Notifier.contact(self).deliver
end
+
+ # Returns a hash of attributes, according to the attributes existent in
+ # self.class.mail_attributes.
+ def mail_form_attributes
+ self.class.mail_attributes.inject({}) do |hash, attr|
+ hash[attr.to_s] = send(attr)
+ hash
+ end
+ end
end
end
View
8 lib/mail_form/shim.rb
@@ -29,14 +29,6 @@ def initialize(params={})
end unless params.blank?
end
- # Returns a hash of attributes, according to the attributes existent in
- # self.class.mail_attributes.
- def attributes
- self.class.mail_attributes.each_with_object({}) do |attr, hash|
- hash[attr.to_s] = send(attr)
- end
- end
-
# Always return true so when using form_for, the default method will be post.
def new_record?
true
View
2 lib/mail_form/views/mail_form/contact.erb
@@ -1,6 +1,6 @@
<h4 style="text-decoration:underline"><%= message.subject %></h4>
-<% @resource.attributes.each do |attribute, value|
+<% @resource.mail_form_attributes.each do |attribute, value|
next if value.blank? %>
<p><b><%= @resource.class.human_attribute_name(attribute) %>:</b>

0 comments on commit 9d6c57e

Please sign in to comment.