Skip to content

Instantly share code, notes, and snippets.

@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
require "time"
require "date"
class Date
def to_time
Time.local(year, month, day)
end
end
class Time
@nruth
nruth / cookie_steps.rb
Created July 21, 2010 17:16
Testing login "remember me" feature with Capybara (rack::test or selenium) - deleting the session cookie (only)
@macek
macek / 20101004063749_create_photos.rb
Created October 4, 2010 22:38
How to save uploaded files to your database in Rails
# db/migrate/20101004063749_create_photos.rb
class CreatePhotos < ActiveRecord::Migration
def self.up
create_table :photos do |t|
t.string :name, :null => false
t.binary :data, :null => false
t.string :filename
t.string :mime_type
t.timestamps
@trevorturk
trevorturk / cache_assets.rake
Created January 13, 2011 17:38
rake deploy and rake cache_assets for heroku
desc "cache assets"
task :cache_assets => :environment do
paths = ['public/javascripts/all.js', 'public/stylesheets/all.css']
puts "-----> caching assets..."
paths.each do |path|
puts "-----> #{path}"
end
@ryanb
ryanb / application.html.erb
Created January 19, 2011 19:31
Example of very simple password authentication.
<!-- layout file -->
<% if current_user %>
Welcome <%= current_user.username %>. Not you? <%= link_to "Log out", logout_path %>
<% else %>
<%= link_to "Sign up", signup_path %> or <%= link_to "log in", login_path %>.
<% end %>
@jiren
jiren / sprite_datauri_writer.rb
Created January 20, 2011 14:57
This generates 2 css files - sprite image and a css along with a datauri css.
#! /usr/local/bin/ruby -w
# This simple program takes a bunch of images and creates a sprite image along with the corrosponding
# css. It also generates the datauri css. So, we can serve performance optimized CSS depending on the
# Browsers.
#
# Browsers which do not support datauri, like IE7 and below get the sprite image and the sprite css.
# Browsers which support datauri, get the datauri.css
#
# Usage:
@gunn
gunn / _form_carrier_wave_file.html.haml
Created March 24, 2011 10:14
Carrierwave support for rails_admin
= label_tag "#{field.abstract_model.to_param}_#{field.name}", field.label
.input
- if field.bindings[:object].send("#{field.name}_url")
.row
= link_to field.bindings[:object].send("#{field.name}_url")
%br
= form.check_box "remove_#{field.name}"
= form.label "remove_#{field.name}", "Remove existing #{field.label.downcase}", class: "inline"
.row
= form.file_field field.name, class: "fileUploadField #{field.has_errors? ? "errorField" : nil}"
@joshuap
joshuap / environment.rb
Created April 29, 2011 19:37
Net:HTTP enabled URI Validator for Rails 3
...
require 'uri_validator'
@chrisbloom7
chrisbloom7 / README.md
Created June 6, 2011 07:16
A cheap knock off of the default validates_length_of validator, but checks the filesize of a Carrierwave attachment

Note that this validation runs both after the file is uploaded and after CarrierWave has processed the image. If your base uploader includes a filter to resize the image then the validation will be run against the resized image, not the original one that was uploaded. If this causes a problem for you, then you should avoid using a resizing filter on the base uploader and put any specific size requirements in a version instead.

So instead of this:

require 'carrierwave/processing/mini_magick'