Get Homebrew installed on your mac if you don't already have it
Install highlight. "brew install highlight". (This brings down Lua and Boost as well)
class ArticleImageUploader < ImageUploader | |
process :fix_exif_rotation | |
process :strip | |
process :convert => 'jpg' | |
process :quality => 85 # Percentage from 0 - 100 | |
version :gallery_thumb do | |
process :resize_to_fill => Settings.images.article_images.processing.gallery_thumb #44x44 | |
end |
# Avoid problems when running Capybara specs before regular ones, and fix the | |
# "Could not find a valid mapping for X". Part of the solution is to use the | |
# Devise test helpers as explained on link A, but then you need to clear the | |
# fabricated objects, as explained on link B. Here's the equivalent code when | |
# using the Fabrication gem | |
# | |
# A - http://stackoverflow.com/questions/4230152/mocks-arent-working-with-rspec-and-devise | |
# B - http://stackoverflow.com/questions/6363471/could-not-find-a-valid-mapping-for-user-only-on-second-and-successive-t | |
if Rails.env.development? || Rails.env.test? | |
ActionDispatch::Callbacks.after do |
# Example with basic types | |
--- | |
hash: | |
string: some text | |
number: 12345 | |
array_of_bool: [on, off, true, false, yes, no] | |
ruby symbol: :symbol | |
array: | |
- item one | |
- item two |
Get Homebrew installed on your mac if you don't already have it
Install highlight. "brew install highlight". (This brings down Lua and Boost as well)
#Model | |
@user.should have(1).error_on(:username) # Checks whether there is an error in username | |
@user.errors[:username].should include("can't be blank") # check for the error message | |
#Rendering | |
response.should render_template(:index) | |
#Redirecting | |
response.should redirect_to(movies_path) |
class ApplicationController < ActionController::Base | |
... | |
#Problem: | |
#In rails 3.0.1+ it is no longer possible to do this anymore; | |
# rescue_from ActionController::RoutingError, :with => :render_not_found | |
# | |
#The ActionController::RoutingError thrown is not caught by rescue_from. | |
#The alternative is to to set a catch-all route to catch all unmatched routes and send them to a method which renders an error | |
#As in http://techoctave.com/c7/posts/36-rails-3-0-rescue-from-routing-error-solution |
# encoding: utf-8 | |
require_relative 'type' | |
require 'yaml' | |
30.times {puts} | |
sleep 2 | |
command '"That was: #{event.name} #{Location.current} #{Date.today.year}"', "=> That was: Railsgirls Berlin 2012" |
#app/controllers/application_controller.rb | |
class ApplicationController < ActionController::Base | |
def opensearch | |
response.headers['Content-Type'] = 'application/opensearchdescription+xml; charset=utf-8' | |
end |
body { | |
font-family: Helvetica, arial, sans-serif; | |
font-size: 14px; | |
line-height: 1.6; | |
padding-top: 10px; | |
padding-bottom: 10px; | |
background-color: white; | |
padding: 30px; } | |
body > *:first-child { |
var user = { | |
validateCredentials: function (username, password) { | |
return ( | |
(!(username += '') || username === '') ? { error: "No Username Given.", field: 'name' } | |
: (!(username += '') || password === '') ? { error: "No Password Given.", field: 'pass' } | |
: (username.length < 3) ? { error: "Username is less than 3 Characters.", field: 'name' } | |
: (password.length < 4) ? { error: "Password is less than 4 Characters.", field: 'pass' } | |
: (!/^([a-z0-9_-]+)$/i.test(username)) ? { error: "Username contains invalid characters.", field: 'name' } | |
: false | |
); |