This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
before :save, :set_order_no | |
def set_order_no | |
order_no = next_order_no if order_no.nil? || order_no.blank? | |
end | |
private | |
def next_order_no | |
... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# dm modle | |
class SampleOrder | |
include DataMapper::Resource | |
property :id, Serial | |
property :order_no, String | |
... | |
before :save, :set_order_no | |
def set_order_no |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def send_email() | |
begin | |
mailer = Merb::Mailer.new( | |
:from => 'your from', | |
# hack: Net::SMTP.send_message does not send msg to cc | |
:to => 'your_to list', | |
:subject => 'your subject', | |
:text => 'content') | |
mailer.deliver! | |
rescue => exception |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Mailer | |
# Sends the mail using SMTP. | |
def net_smtp | |
Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE) | |
Net::SMTP.start(config[:host], config[:port].to_i, config[:domain], | |
config[:user], config[:pass], config[:auth]) { |smtp| | |
smtp.send_message..... | |
} | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Merb::BootLoader.after_app_loads do | |
# for the mailer - gmail | |
Merb::Mailer.config = { | |
:host => 'smtp.gmail.com', | |
:port => '587', | |
:user => 'your_name@your_domain', | |
:pass => 'your_pass', | |
:auth => :plain, # :plain, ;login, :cram_md5 | |
:domain => "your_domain" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
def self.available_controllers(name) | |
roles = Role.all(:name => name, :authorizable_type.not => nil) | |
exists_controllers = roles.collect{|r| r.authorizable_type} | |
controllers = Application.subclasses_list.to_a.sort | |
controllers - exists_controllers | |
end | |
def authorizable_class | |
return nil if authorizable_type.nil? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Role.rb | |
... | |
def authorizable_class | |
return nil if authorizable_type.nil? | |
klass = begin | |
authorizable_type.split("::").inject(Object){|x, y| x.const_get(y)} | |
rescue NameError => e | |
msg = "Class not found: `#{authorizable_type}'" | |
Merb.logger.warn!(msg) | |
nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# DM 0.9.9 | |
users = User.all | |
names = users.collect{|u| u.first_name} | |
names.uniq # works well, return all the names | |
names.uniq! # diff from MRI: return nil | |
# MRI | |
a = [1, 2, 3, 1, 2] | |
a.uniq #[3] | |
puts a #[1, 2, 3, 1, 2] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Employee | |
include DataMapper::Resource | |
property :id, Serial | |
property :name, String | |
... | |
end | |
class Manager < Employee | |
property :position, String, :default => 'manager' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo gem install do_mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config |