Skip to content

Instantly share code, notes, and snippets.

View ohammersmith's full-sized avatar

Otto Hammersmith ohammersmith

View GitHub Profile
<% if ENV["RAILS_ENV"] == "development" %>
<div id="debug">
<a href="#" onclick="Element.toggle('params_debug_info'); return false">params</a> | <a href="#" onclick="Element.toggle('session_debug_info'); return false">sessions</a>
<fieldset id="params_debug_info" class="debug_info" style="display:none">
<legend>params</legend> <%= debug(params) %>
</fieldset>
<fieldset id="session_debug_info" class="debug_info" style="display:none">
When /^I fill in the country for the degree with "(.*)"$/ do |value|
within("#degrees") do
fill_in("Country", value)
end
end
IRC
========
Install Notes
-------------
1. server (ie. irc.freenode.net)
2. port is normally 6667 / 9999 for ssl
3. the room field can support multiple rooms (comma separated)
4. the password field is for the server password
@ohammersmith
ohammersmith / 00-fully-operational-rake-routes.txt
Created April 14, 2009 23:41
Working out nested resources with a self-referential association
(in /Users/otto/Desktop/Incubator/shallow_routes)
communities GET /communities(.:format) {:action=>"index", :controller=>"communities"}
POST /communities(.:format) {:action=>"create", :controller=>"communities"}
new_community GET /communities/new(.:format) {:action=>"new", :controller=>"communities"}
edit_community GET /communities/:id/edit(.:format) {:action=>"edit", :controller=>"communities"}
community GET /communities/:id(.:format) {:action=>"show", :controller=>"communities"}
PUT /communities/:id(.:format) {:action=>"update", :controller=>"communities"}
DELETE /communities/:id(.:format) {:action=>"destroy", :controller=>"communities"}
community_forums GET /communities/:community_id/forums(.:format) {:action=>"index", :controller=>"forums"}
<% form_tag(:action => "create") do %>
<% for question in @questions %>
<%= h question[:name] %>
<%= hidden_field_tag "responses[][question_id]", question[:id] %>
<%= check_box_tag "responses[][flag]" %> <br />
<% end %>
<%= submit_tag "Post" %>
<% end -%>
<h1>Custom form demo</h1>
<!-- maybe the real thing -->
<% form_tag(:action => "create") do %>
<% for question in @questions %>
<%= hidden_field_tag "responses[][#{question.id}][type]", question.q_type %>
<% if question.q_type == "checkbox" %>
Checkbox <br/>
Given /^WH([O]+)AH (.*)$/ do |ohs, actual_step|
ohs.length.times { sleep 10 }
Given actual_step
end
# save and open page before
Given /^SAOP([BA]) (.*)$/ do |before_or_after, actual_step|
save_and_open_page if before_or_after == "B"
Given actual_step
save_and_open_page if before_or_after == "A"
describe "#route_for" do
it "should be nested shallowly under forums as topics" do
params_from(:get, '/forums/123/topics').should == {:controller => "forum_posts", :action => "index", :forum_id => "123" }
end
it "should be nested shallowly under topics as posts" do
params_from(:get, '/topics/123/posts').should == {:controller => "forum_posts", :action => "index", :topic_id => "123" }
params_from(:get, '/posts/321').should == {:controller => "forum_posts", :action => "show", :id => "321" }
end
Given /^There (?:is|are) (\d+|a) (.*?)(.*?)(?: with "(.*?)" for (.*?))?$/ do |count, model, factory_suffix, value, attribute|
count = 1 if count == "a"
factory_name = model.singularize << factory_suffix.gsub(" ", "_")
if attribute and value
count.to_i.times { Factory(factory_name.to_sym, attribute.to_sym => value) }
else
count.to_i.times { Factory(factory_name.to_sym) }
end
end
irb(main):001:0> h = {:foo => "bar", :bar => "foo"}
=> {:bar=>"foo", :foo=>"bar"}
irb(main):002:0> h
=> {:bar=>"foo", :foo=>"bar"}
irb(main):003:0> h.respond_to?(:all?)
=> true
irb(main):004:0> h.all? { |k, v| puts k }
bar
=> false