Saturday progress

This commit is contained in:
2013-01-19 17:14:33 +01:00
parent db1a6ac96b
commit 702bd41ee4
36 changed files with 128 additions and 57 deletions
+19 -5
View File
@@ -31,7 +31,6 @@ class Supplier
has_many :sections, dependent: :destroy
after_create :add_section_on_create
after_create :send_creation_notifications
view :by_email, key: :email
@@ -39,7 +38,7 @@ class Supplier
validates :iens_profile, numericality: {allow_blank: true}
def location=(val)
lat, lng = val.strip.split(/[ ,]+/).map(&:to_f)
lat, lng = val.is_a?(Array) ? val : val.strip.split(/[ ,]+/).map(&:to_f)
self.lat = lat
self.lng = lng
end
@@ -88,14 +87,29 @@ class Supplier
self.open = false
save
end
# Find a user by its confirmation token and try to confirm it.
# If no user is found, returns a new user with an error.
# If the user is already confirmed, create an error for the user
# Options must have the confirmation_token
#
# Overwrite devise method for mail sending
def self.confirm_by_token(confirmation_token)
confirmable = find_or_initialize_with_error_by(:confirmation_token, confirmation_token)
confirmable.confirm! if confirmable.persisted?
confirmable.send_creation_notifications if confirmable.errors.empty?
confirmable
end
def send_creation_notifications
SupplierMailer.creation(self).deliver
end
private
def add_section_on_create
@section = Section.create supplier: self, title: I18n.t('supplier.section.first_section_title')
end
def send_creation_notifications
SupplierMailer.creation(self).deliver
end
end
+11 -2
View File
@@ -1,5 +1,6 @@
class Table
include SimplyStored::Couch
per_page_method :limit_value #kaminari
property :number, type: Fixnum, default: 1
property :position_x, type: Float
@@ -21,8 +22,16 @@ class Table
view :by_number, key: :number
def self.for_supplier(supplier, options = {})
startkey = options[:from_number].present? ? [supplier.id, options.delete(:from_number).to_i] : [supplier.id]
endkey = options[:to_number].present? ? [supplier.id, options.delete(:to_number).to_i]: [supplier.id, {}]
startkey = if from_number = options.delete(:from_number).presence
[supplier.id, from_number.to_i]
else
[supplier.id]
end
endkey = if to_number = options.delete(:to_number).presence
[supplier.id, to_number.to_i]
else
[supplier.id, {}]
end
total_entries = database.view(by_supplier_id_and_number({startkey: startkey, endkey: endkey, include_docs: false, reduce: true}))
options[:total_entries] = total_entries