Always store your Paperclip attachments in a separate folder per environment
Paperclip attachments can collide across development, test, and parallel test processes when they share one storage tree. Separate environment-specific paths prevent overwritten files and missing test data.
Nginx Error "413 Request Entity Too Large"
Nginx returns 413 Request Entity Too Large when client_max_body_size is below the upload size limit, often during file uploads.
Check whether a Paperclip attachment exists
Paperclip attachment checks can give false positives because the attribute returns an attachment object. Use exists? to test whether a file is actually attached.
Insert multiple blank rows into an OpenOffice.org/LibreOffice Calc spreadsheet
Insert several empty rows in Calc at once by selecting multiple row headers and using Insert Rows; the new rows inherit the style from above.
How to diff two strings in Ruby
Compute readable differences between two strings in Ruby or Rails with the differ gem, including word, line, and character comparisons plus HTML or color output.
Responding to the OPTIONS HTTP method request in Rails: Getting around the Same Origin Policy
Rails applications can answer browser preflight requests and allow controlled cross-origin access by handling OPTIONS requests with CORS headers.
Cross-Origin Resource Sharing - Wikipedia
Browser requests across domains are blocked by the same-origin policy unless a service allows them with CORS; it replaces JSONP and supports regular XMLHttpRequest and non-GET methods.
JSONP - Wikipedia
Cross-origin web pages cannot normally communicate, but <script> requests can pull executable JavaScript around same-origin limits. JSONP uses this loophole to load dynamic data from other origins.
Web Operations 101 For Developers
Web application developers increasingly need operational knowledge beyond coding, testing, and deploying. Traditional development workflows now overlap with running and maintaining production systems.
Use Capybara on any HTML fragment or page
Capybara matchers can be applied to standalone HTML fragments or strings, not only full pages, making fragment assertions easier in test suites.
Zip files with Ruby
Create ZIP archives in Ruby with zipruby; add existing files, string buffers, and directories using Ruby bindings for libzip.
Downloading files from Ruby on Rails
Serving files as downloads in Ruby on Rails uses send_file; it returns the file directly and overrides the normal render response.
Vim: Scroll up/down, keeping your cursor in its row
Keep the cursor on its row while scrolling a Vim buffer, avoiding jumps to the top or bottom of the screen. Default keys move the viewport by a line or half screen.
Thunderbird Addon: Message Archive Options
Sets Thunderbird archive folder date formatting and folder granularity for year and month subfolders, and can modify the A shortcut with Shift, Control, or Alt.
Hide your Selenium browser window with a VNC server
Run Selenium tests in a hidden X session with vncserver, keeping the browser accessible for inspection without adding a gem.
Passenger booting Rails 3 application in wrong environment
Passenger can start a Rails app in the wrong environment unless Apache is configured with the correct RailsEnv or RackEnv setting.
Firefox 3.6 truncates long tables when printing
Firefox 3.6 print output cuts off long tables, often due to CSS floats, overflow rules, or nearby h1 and caption tags.
How to look at hidden X screens
Hidden X displays can be inspected by taking a screenshot of the active display, including Xvfb-backed sessions used for headless tests.
simple_format helper for Javascript
Rough JavaScript equivalent of Rails simple_format for turning plain text into HTML paragraphs and line breaks. Whitespace preservation is not included.
Resque: Work off queues manually
Manual queue processing in Resque specs avoids relying on an external worker while keeping behavior close to real job execution.
Resque: Clearance authentication for dashboard
Resque dashboard access can bypass ApplicationController filters in Rails 3, so a Rack middleware can protect it with Clearance and a remember token.
How to hide your selenium browser window with "headless"
Selenium browser windows can steal focus during Cucumber acceptance tests; headless with xvfb keeps them hidden while running Selenium WebDriver through Capybara.
A few hints when upgrading to Ruby 1.9
Ruby 1.9 upgrades in Rails apps often fail because of gem incompatibilities, lambda arity issues, and encoding mismatches between files, strings, and databases.
Change file permissions with Ruby
File.chmod sets Unix file permissions in Ruby, where the leading zero matters for octal mode values.