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 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
... | |
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
1. Set the mysql bin path if you installed it by yourself in /usr/local/mysql | |
#you have to set your mysql bin on your path: | |
PATH=$PATH:/usr/local/mysql/bin | |
2. Remove the default mysql executable files | |
$ sudo mv /usr/bin/mysql_config usr/bin/mysql_config.old | |
$ sudo mv /usr/bin/mysql usr/bin/mysql |
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 |
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
install do-mysql | |
Installing do_mysql-0.9.11 | |
Building native extensions. This could take a while... | |
ERROR: Failed to build gem native extension. | |
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb merb:gem:install | |
checking for mysql.h... no | |
checking for main() in -lmysqlclient... no | |
checking for mysql_query()... no | |
checking for mysql_ssl_set()... no |