Don’t simply test for the presence of the magic Paperclip attribute, it will return a paperclip Attachment object and thus always be true:
- if user.photo.present? # always true
= image_tag(user.photo.url)
=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') |
var simpleFormatRE1 = /\r\n?/g; | |
var simpleFormatRE2 = /\n\n+/g; | |
var simpleFormatRE3 = /([^\n]\n)(?=[^\n])/g; | |
function simpleFormat(str) { | |
var fstr = str; | |
fstr = fstr.replace(simpleFormatRE1, "\n") // \r\n and \r -> \n | |
fstr = fstr.replace(simpleFormatRE2, "</p>\n\n<p>") // 2+ newline -> paragraph | |
fstr = fstr.replace(simpleFormatRE3, "$1<br/>") // 1 newline -> br | |
fstr = "<p>" + fstr + "</p>"; | |
return fstr; |
# utterly crappy proof-of-concept that works. for me. today. | |
task :freeze do | |
require 'bundler_auto_update' | |
include Bundler::AutoUpdate | |
locked_gems = IO.read('Gemfile.lock').match(/^GEM.*^PLATFORMS$/m).to_s.split("\n").grep(/^\s{4}\w/).map(&:strip) | |
locked_gems = locked_gems.inject({}) { |result, gem| result.merge!(Hash[[gem.gsub(/\(|\)/, '').split]]); result} | |
gemfile = Gemfile.new | |
gemfile.gems.each do |g| |
# Resize selenium browser window to avoid Selenium::WebDriver::Error::MoveTargetOutOfBoundsError errors | |
# | |
# Example usage with Rspec (in spec/support/spec_helper.rb): | |
# | |
# config.before(:each) do | |
# set_selenium_window_size(1250, 800) if Capybara.current_driver == :selenium | |
# end | |
# | |
def set_selenium_window_size(width, height) | |
window = Capybara.current_session.current_window.resize_to |
# I got tired of uploading to /tmp then moving to the correct location, so these two convenience methods will save you a lot of time in the long run. | |
# Helper method to upload to /tmp then use sudo to move to correct location. | |
def put_sudo(data, to) | |
filename = File.basename(to) | |
to_directory = File.dirname(to) | |
put data, "/tmp/#{filename}" | |
run "#{sudo} mv /tmp/#{filename} #{to_directory}" | |
end |
I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.
If you want to roll up all of these into a single jQuery plugin check out Sharrre
Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.
/* | |
Element to slide gets the following CSS: | |
max-height: 0; | |
opacity: 0; | |
overflow: hidden; | |
transition: max-height 0.4s ease 0s; | |
*/ | |
/** | |
* Like jQuery's slideDown function - uses CSS3 transitions |
# in controller | |
# for local files | |
send_file '/path/to/file', :type => 'image/jpeg', :disposition => 'attachment' | |
# for remote files | |
require 'open-uri' | |
url = 'http://someserver.com/path/../filename.jpg' | |
data = open(url).read | |
send_data data, :disposition => 'attachment', :filename=>"photo.jpg" |