Skip to content

Instantly share code, notes, and snippets.

# spec_helper.rb
# Helper method to adding the fixtures into the tests
def fixtures(*files)
files.each do |file|
klass = begin
Kernel::const_get(
Extlib::Inflection.classify(
Extlib::Inflection.singularize(file.to_s)))
rescue
nil
# Helper method to adding the fixtures into the tests
def fixtures(*files)
files.each do |file|
klass = begin
Kernel::const_get(Extlib::Inflection.classify(Extlib::Inflection.singularize(file.to_s)))
rescue
nil
end
entries = YAML::load_file(File.dirname(__FILE__) + "/fixtures/#{file}.yml")
# do a migrate to create the table to clear the records
@zhhz
zhhz / link_to_action with confirmation.rb
Created November 11, 2008 19:20
link_to_action with confirmation
<VirtualHost *:80>
ServerName app.myapp.com
DocumentRoot /Users/zhonghai/apps/ruby/current/public
# setting the env to development
RackEnv development
</VirtualHost>
# setting the env to development
RackEnv development
<VirtualHost *:80>
ServerName app.myapp.com
DocumentRoot /Users/zhonghai/apps/ruby/current/public
</VirtualHost>
# dm 0.9.8 breaks YAML.dump
zooo = Zoo.all
File.open('zoo.yaml', 'w'){|f| YAML.dump(zooo, f)}
zooo = Zoo.all
File.open('zoo.yaml', 'w'){|f| f.puts zooo.to_yaml}
z1 = Zoo.all(:condition.....)
z1.to_yaml # this OK
z2 = Zoo.all(:condition...)
z2.to_yaml # this OK
z3 = z1 + z2
z3.to_yaml # bam!. ERROR
@zhhz
zhhz / ack.vim
Created December 22, 2008 14:12
" all credits to antoine,
" more details see: http://blog.ant0ine.com/2007/03/ack_and_vim_integration.html
function! Ack(args)
let grepprg_bak=&grepprg
set grepprg=ack\ -H\ --nocolor\ --nogroup
execute "silent! grep " . a:args
botright copen
let &grepprg=grepprg_bak
endfunction
@zhhz
zhhz / form.html
Created January 18, 2009 00:49
merb_form.html.erb
<% @pos.each |purchase_order| do %>
<%= form_for(purchase_order, :action => url(:create_po_purchasing_shopping_lists)) do %>
<%= hidden_field :name => "counter", :value => count %>
<%= partial 'purchasing/purchase_orders/basic_form', :po => po %>
<button class="positive" type="submit">
<img alt="create" src="/images/icons/tick.png"></img>
Create
</button>
<% end =%>
<% end %>