Skip to content

Instantly share code, notes, and snippets.

@andyferra
andyferra / gist:13036
Created Sep 26, 2008
Generates per_page links for will_paginate
View gist:13036
def per_page_links(collection, options={})
unless collection.empty?
separator = options[:seperator] || ' '
css_class = options[:class] || 'per_page_links'
param = options[:param] || :per_page
per_page = collection.first.class.per_page
options = [per_page/2, per_page, per_page*2]
value = params[param] || per_page.to_s
link = lambda {|p| url_for(params.merge({param => p}))}
item = lambda {|p, current_value| current_value == p.to_s ? content_tag(:span, p, :class => 'current') : link_to(p, link.call(p)) }
@andyferra
andyferra / gist:12991
Created Sep 25, 2008
Generates a per_page select for will_paginate
View gist:12991
def per_page_select(collection, name=nil, value=nil, options={})
unless collection.empty?
per_page = collection.first.class.per_page
name = name || 'per_page'
value = value || params[:per_page] || per_page.to_s
before = options[:before_default] || ["#{per_page/2}"]
after = options[:after_default] || ["#{per_page*2}"]
choices = options_for_select(before + ["#{per_page}"] + after, value)
select_tag name, choices, options
end
View gist:27549
## In application.js
$(document).ready(function() {
$('table.search_results tbody tr').click(function() {
alert($(this).children('a:first-child').attr('href'));
});
});
## In view.html
View gist:29239
Event.addBehavior({
'#my_selector': function() {
// code that only gets executed when something with the id 'my_selector' exists
}
});
View gist:32291
jQuery.fn.exists = function(fn) {
if (this.length) fn(this);
return this;
}
View gist:33873
## models/post.rb
class Post
include DataMapper::Resource
property :id, Serial
property :title, String, :nullable => false
property :body, Text
property :created_at, DateTime
property :updated_at, DateTime
View gist:34645
## config/router.rb
Merb.logger.info("Compiling routes...")
Merb::Router.prepare do
match("/(:args)", :args => /.*/).
to(:controller => "default", :action => 'index')
end
## app/controllers/default.rb
View gist:35597
## /Library/Application Support/Macromedia/mm.cfg
ErrorReportingEnable=1
TraceOutputFileEnable=1
View gist:49132
# -*- ruby -*-
module Autotest::RedGreen
Autotest.send(:alias_method, :real_ruby, :ruby)
Autotest.send(:define_method, :ruby) do |*args|
real_ruby + %[ -rrubygems -e "require 'redgreen'" ]
end
# Clean the output so other modules can work correctly
Autotest.add_hook :ran_command do |at|
View gist:49242
*** Exception SecurityError in spawn manager (Insecure operation - directory?) (process 745):
from /opt/local/lib/ruby/gems/1.8/gems/passenger-2.0.6/lib/passenger/application.rb:45:in `directory?'
from /opt/local/lib/ruby/gems/1.8/gems/passenger-2.0.6/lib/passenger/application.rb:45:in `detect_framework_version'
from /opt/local/lib/ruby/gems/1.8/gems/passenger-2.0.6/lib/passenger/spawn_manager.rb:193:in `spawn_rails_application'
from /opt/local/lib/ruby/gems/1.8/gems/passenger-2.0.6/lib/passenger/spawn_manager.rb:126:in `spawn_application'
from /opt/local/lib/ruby/gems/1.8/gems/passenger-2.0.6/lib/passenger/spawn_manager.rb:251:in `handle_spawn_application'
from /opt/local/lib/ruby/gems/1.8/gems/passenger-2.0.6/lib/passenger/abstract_server.rb:317:in `__send__'
from /opt/local/lib/ruby/gems/1.8/gems/passenger-2.0.6/lib/passenger/abstract_server.rb:317:in `main_loop'
from /opt/local/lib/ruby/gems/1.8/gems/passenger-2.0.6/lib/passenger/abstract_server.rb:168:in `start_synchronously'
from /opt/