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 Person < ActiveRecord::Base | |
has_many :addresses | |
validates_associated :addresses | |
validates_length_of :addresses, :less_than => 5 | |
before_save :save_addresses | |
def addresses_from_form=(address_hashes) | |
addresses = address_hashes.collect{ |address_hash| Address.new(address_hash) } | |
self.addresses.target = addresses # sets the association target, doesn't trigger any saves or destroys | |
# this works because validates_associated basically just does self.addresses.each{ |address| address.valid? } |
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
require 'rubygems' | |
require 'activesupport' | |
dt = DateTime.now | |
puts dt.to_f | |
# => 1240455468.91318 | |
t = YAML.load(dt.to_yaml) | |
puts t.class.name | |
# => Time | |
puts t.to_f | |
# => 1240455468.0 |
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
require 'rubygems' | |
require 'activesupport' | |
dt = DateTime.now | |
puts dt.utc.to_f | |
# => 1240456717.12572 | |
puts dt.to_time.to_f | |
# => 1240456717.12572 | |
puts dt.utc.to_time.to_f | |
# => 1240455680.0 | |
puts dt.to_time.utc.to_f |
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
if File.exists?("my_git_ignored_file.yml") | |
::AppConfig = ApplicationConfiguration.new("my_git_ignored_file.yml") | |
else | |
::AppConfig = ApplicationConfiguration.new("my_normal_config_file.yml") | |
end | |
AppConfig.use_environment!(RAILS_ENV) |
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
# app_config.yml | |
# -------------- | |
# development: | |
# env: dev | |
# server: dev.domain.com | |
# production: | |
# env: prod | |
# server: prod.domain.com | |
# | |
# local_override.yml |
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251"> | |
</head> | |
<body></body> | |
</html> |
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 ApplicationController < ActionController::Base | |
param_accessible [:id, :page] | |
end | |
# This will filter any param except for :id and :page for ALL controllers in your entire application (because you're calling param_accessible on ApplicationController). |
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
shared_context "for_extending" do | |
context "extended with MyModule" do | |
before(:all){ subject.extend(MyModule) } | |
it "should define #some_method" do | |
subject.should respond_to(:some_method) | |
end | |
yield | |
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
describe Object do | |
context "extented with MyModule" do | |
before(:all){ subject.extend(MyModule) } | |
it "should define #some_method" do | |
subject.should respond_to(:some_method) | |
end | |
end | |
end | |
describe Class do |
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
#!/bin/bash | |
RVM_BIN=/usr/local/rvm/bin/rvm | |
EDITOR_UI=/home/onespot/editor-ui/current | |
$RVM_BIN 1.9.2@editor-ui ruby $EDITOR_UI/bin/openx_report.rb -e production > $EDITOR_UI/log/openx_report.log 2>&1 |
OlderNewer