RAILS_DEFAULT_LOGGER.error
Tag Archive for ruby
Logging from inside a rails model
Load all *.jar files in RAILS_ROOT/lib
# for JRuby, load JDBC adapter and all the .jar files in lib. if (RUBY_PLATFORM =~ /java/) require 'jdbc_adapter' Dir.foreach(File.join(RAILS_ROOT, 'lib')) do |file| if m = /([^s]+).jar$/.match(file) require m[1] end end end
String replace in ruby
"Hello World".gsub("Hello", "Bye")
mongrel_cluster capistrano recipe
, :restart ].each do |t|
desc "#{t.to_s.capitalize} the mongrel appserver"
task t, :roles => :app do
#invoke_command checks the use_sudo variable to determine how to run the mongrel_rails command
invoke_command "mongrel_rails cluster::#{t.to_s} -C #{mongrel_conf}", :via => run_method
end
end
end
desc "Custom restart task for mongrel cluster"
task :restart, :roles => :app, :except => { :no_release => true } do
deploy.mongrel.restart
end
desc "Custom start task for mongrel cluster"
task :start, :roles => :app do
deploy.mongrel.start
end
desc "Custom stop task for mongrel cluster"
task :stop, :roles => :app do
deploy.mongrel.stop
end
end
source
Install rmagick dependencies on ubuntu/debian
apt-get install libmagick9-dev
Relacionar dos tablas por dos caminos diferentes
#tablas noticias(id,titulo) boletins(id,portada_id,titulo) boletins_noticias(id,noticia_id,boletin_id) #modelos class Boletin < ActiveRecord::Base has_and_belongs_to_many :noticias belongs_to :portada, :foreign_key => :portada_id, :class_name => 'Noticia' end class Noticia < ActiveRecord::Base has_and_belongs_to_many :boletins end #pruebas en consola bole=Boletin.new(:titulo => 'Boletin numero uno') bole.save noti=Noticia.new(:titulo => 'Noticia numero uno') noti.save portada=Noticia.new(:titulo => 'Noticia de portada') portada.save bole.noticias << noti bole.portada=portada
Category: Uncategorized |
Tags: activerecord, belongsto, hasmany, rails, relacin, relaciones, ror, ruby
Install rmagick on Ubuntu
sudo apt-get remove --purge librmagick-ruby-doc librmagick-ruby1.8 sudo apt-get install libmagick9-dev ruby1.8-dev sudo gem install rmagick
Install rmagick on Ubuntu
sudo apt-get remove --purge librmagick-ruby-doc librmagick-ruby1.8 sudo apt-get install libmagick9-dev ruby1.8-dev sudo gem install rmagick
ruby spring proper case
str = "how are you? are you feeling good?"
puts str.split(/s+/).each{ |word| word.capitalize! }.join(' ')
Category: Uncategorized |
Tags: ruby
Apache regex
regex = /^(pms(?!/attachments).*)$/
patterns = ["pms", "pms/attachments", "pms/asdf", "pms/attachments/stuff.txt", "pms/asdf/werqw.txt"]
patterns.each do |p|
matches = p.match(regex)
if matches
puts "? = [#{matches}]"
end
end
nil