ActiveRecord reconnect to database
// my Merb consoles drop the db connection after the mysql timeout; I'd rather not reload the whole environment
ActiveRecord::Base.connection.reconnect!
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)
ActiveRecord::Base.connection.reconnect!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> <title>Events: <%= controller.action_name %></title> <%= stylesheet_link_tag 'style' %> </head> <body> <p style="color: green"><%= flash[:notice] %></p> <%= yield %> </body> </html>
Event.find( :all, :conditions => [ "title like :search or description like :search", {:search => "%Tiki%"}] )
#!/bin/sh svn remove log/* svn commit -m"removing log files" svn propset svn:ignore "*.log" log/ svn update log/ svn commit -m 'Ignoring all files in /log/ ending in .log' svn move config/database.yml config/database.example svn commit -m 'Moving database.yml to database.example to provide a template for anyone who checks out the code' svn propset svn:ignore "database.yml" config/ svn update config/ svn commit -m 'Ignoring database.yml' svn remove tmp/* svn propset svn:ignore "*" tmp/ svn update tmp/ svn commit -m "ignore tmp/ content from now" svn propset svn:ignore ".htaccess" config/ svn update config/ svn commit -m 'Ignoring .htaccess' svn propset svn:ignore "dispatch.fcgi" config/ svn update config/ svn commit -m 'Ignoring dispatch.fcgi'
script/plugin install [name of plugin, or the url to the desired plugin]
# 1) make yrself a user and stop being root # 2) main web stack + ruby sudo aptitude install -y make screen sudo aptitude install -y apache2 php5 mysql-server sudo aptitude install -y subversion postfix sudo aptitude install -y ruby1.8 ruby1.8-dev rubygems irb sudo aptitude install -y imagemagick librmagick-ruby1.8 librmagick-ruby-doc libfreetype6-dev xml-core # 3) gemz # rubygems appears to be broken as hell. # gem update --system does squat # had to manually d/l rubygems 1.0.1, ruby setup.rb wget http://rubyforge.org/frs/download.php/29548/rubygems-1.0.1.tgz tar xzvf rubygems-1.0.1.tgz cd rubygems-1.0.1 sudo ruby setup.rb sudo gem install rails mongrel merb map_by_method
jQuery.ajaxSetup({ ‘beforeSend’: function(xhr) {xhr.setRequestHeader(“Accept”, “text/javascript”)} })
def decapitalize! replace (self.reverse.chop + self.reverse.last.downcase).reverse end def decapitalize dup.decapitalize! end
myresource_path(:id => myId, :extra_param => extraId, :extra_param2 => blah)
myresource/myId?extra_param=extraId&extra_param2=blah
class Something < ActiveRecord::Base # Validations validate :validate_state_change # State Machine States acts_as_state_machine :initial => :new state :new state :enabled, :after => :after_enabled state :disabled, :after => :after_disabled # State Machine Events event :enabled do transitions :from => :new, :to => :enabled transitions :from => :disabled, :to => :enabled end event :disabled do transitions :from => :new, :to => :disabled transitions :from => :enabled, :to => :disabled end # Instance Methods def validate_state_change return if new_record? old = self.class.find(id) old_state = old.state new_state = self.state self.state = old_state if old_state != new_state begin if self.method("#{new_state}!").call != true errors.add(:state, "cannot transition from #{old_state} to #{new_state}") end rescue NameError end self.state = new_state end end end