Skip to content

Instantly share code, notes, and snippets.

Application Helpers
def block_to_partial(partial_name, options = {}, &block)
options.merge!(:body => capture(&block))
concat(render(:partial => partial_name, :locals => options))
end
# Create as many of these as you like, each should call a different partial
# 1. Render 'shared/rounded_box' partial with the given options and block content
def rounded_box(options = {}, &block)
RJS:
page.insert_html :bottom, 'featured_vendors', :partial => 'base/featured_vendors'
page.select('#featured_vendors_content').last.hide
page.delay(1) do
page.select('#featured_vendors_content').first.remove
page.select('#featured_vendors_content').first.show
end
top - 22:23:31 up 16 days, 23:31, 2 users, load average: 0.00, 0.03, 0.00
Tasks: 171 total, 1 running, 155 sleeping, 0 stopped, 15 zombie
Cpu(s): 1.0%us, 0.2%sy, 0.0%ni, 98.8%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 4050512k total, 2073628k used, 1976884k free, 212720k buffers
Swap: 11863960k total, 2960k used, 11861000k free, 591360k cached
desc "Populate the listing categories"
task :populate_listing_categories => :environment do
ListingCategory.delete_all
# Main Category
@root = ListingCategory.new(:title => "Adults Only")
@root.save! # Save parent
# Women/Men/TG
@root_child1 = @root.children.create(:title => "Find Women")
@root_child2 = @root.children.create(:title => "Find Men")
>> ListingCategory.roots.collect{|e| e.children.map {|t| [t.name, t.id]}}
=> [[["Find Women", 2], ["Find Men", 3]]]
I need to produce this output instead
=> [["Find Women", 2], ["Find Men", 3]]
call_from_site_index.rjs
content = page.select('#facebox .content').first()
content.replace '<div class="content"></div>'
page << "facebox.loading();"
page << "facebox.reveal(\"#{escape_javascript render :partial => 'listing_response'}\", null);"
page << "new Effect.Appear(facebox.facebox, {duration: .3});"
# page.replace 'ListingResponse', :partial => 'listing_response'
def call_from_site_index
call_logic
get_additional_homepage_data
respond_to do |format|
format.js
end
end
def call_from_profile
def get_matching_books query
matching_books = []
bs = GData::Client::BookSearch.new
feed = bs.get("http://books.google.com/books/feeds/volumes?q=#{URI::encode query}").to_xml
feed.elements.each('entry') do |entry|
feed_book = Book.new
feed_book.title = entry.elements['title'].text
feed_book.image_url = entry.elements["link[@rel='http://schemas.google.com/books/2008/thumbnail']"].attribute('href').value
root@theplanet:/var/www/apacite# rake --tasks --trace
(in /var/www/apacite)
rake aborted!
can't activate activesupport (= 2.2.2, runtime) for [], already activated activesupport-2.3.2 for ["rails-2.3.2"]
/usr/local/lib/site_ruby/1.8/rubygems.rb:279:in `activate'
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:35:in `require'
/usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/tasks/misc.rake:18
/usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/tasks/rails.rb:4:in `load'
/usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/tasks/rails.rb:4
/usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/tasks/rails.rb:4:in `each'
title = #{citation.title}
title.capitalize!
title.sub!(/(:\s*)(\w)/){|s| $1 + $2.capitalize }
NoMethodError in Books#show
Showing app/views/books/_citation.html.haml where line #6 raised:
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.capitalize!