Clear a Solr index with acts_as_solr

ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "#{Location.solr_configuration[:type_field]}:#{ModelClass}"))
ActsAsSolr::Post.execute(Solr::Request::Commit.new)

Fixing "A copy of Klass has been removed from the module tree but is still active"

This can happen during development when classes without automatic reloading are pointing to classes with automatic reloading. E.g. some class in lib is calling Model.static_method.

Workaround A

Stop referencing autoloaded classes from static files. If you can't, see workaround B and C.

Workaround B

Make sure the offending file (the one referencing the autoloaded class) is autoloaded, too. You may do this:

# config/application.rb

  config.paths.add 'offending/file/parent/directory', eager_load: true

Workaroun...

Typical .gitignore

log/*
tmp/*
storage/*
db/*.sqlite3
db/schema.rb
db/structure.sql
public/system
.project
.idea/
public/javascripts/all*
public/stylesheets/all*
public/stylesheets/*.css
config/database.yml
*~
*#*
.#*
.DS_Store
webrat-*.html
capybara-*.html
rerun.txt
coverage.data
coverage/*
dump_for_download.dump
.~lock.*
.*.swp
C:\\nppdf32Log\\debuglog.txt

Order of the state_machine callback chain

  1. before transition
  2. before validation
  3. after validation
  4. before save
  5. after save
  6. after transition

Aborting the callback chain

See Cancel the ActiveRecord callback chain.

How to fix "Too many authentic authentication failures" with SSH and/or Capistrano

You are getting when connecting via SSH or deploying with Capistrano (which uses SSH):

Too many authentication failures for username

This is caused by having too many SSH keys added to your keyring or ssh-agent. Your ssh-agent will throw all keys against a server until one matches. Most servers will deny access after 5 attempts.

This issue might come and go as the order of the active SSH keys in your ssh-agent changes.

Quick fix

Have less keys. Up to 5 keys are fine when the SSHD you're connecting to is using the default ...

Why your all.js is empty on staging or production

When you include a non-existing Javascript file, you probably won't notice it during development. But with caching active (on production or staging) Rails will write an empty all.js file without complaining.

Slugs with FriendlyId

Gem to provide nice looking urls ("/blog/the-greatest-bug-i-never-fixed"). If you don't need anything too special (like i18n for the urls) it works as a drop-in-replacement. It basically overwrites #to_param to return the slug, and .find to search by the slug.

Make sure, everywhere you build paths, you use model_path(:id => model) instead of model_path(:id => model.id). You also need to adapt all code using something like .find_by_id. The regular .find is fine.

See the github README for installation instructions.

Don't forget ...

YSlow for Firebug

YSlow analyzes web pages and tells you why they're slow based on the rules for high performance web sites. YSlow is a Firefox add-on integrated with the popular Firebug web development tool.

Nicole Sullivan: "Design Fast Websites" on Yahoo! Video

Web performance expert Nicole Sullivan discusses a set of best practices in the creation of supremely fast, visually impactful web sites.

Agile Ajax » ActionMailer Callbacks: In the Spirit of ActionController Filters » Pathfinder Development

A while back, I had a requirement to persist a record of which email addresses were sent an email through the system. I expected to find callback support for ActionMailer, but was surprised to find that it didn't exist.

Squirrel

Squirrel is an enhancement for ActiveRecord’s find method that allows programmers to query the database using a more Rubyish syntax.

leethal's live-validations at master - GitHub

Reads Active Record's validations and makes them available to live client side javascript

Tagaholic - Console Update With Your Editor

Rails’ script/console makes it easy to fetch, view and edit your database records. But can you edit those records as quickly as you edit code in your text editor? Riiight, like editing our database records in an editor is gonna happen? It already has.

The Bark Blog » Testing Rails Model Plugins

Unfortunately, by default plugin tests are pretty bland. They use the plain unit test suite supplied by Ruby, and not any of the extended Rails test framework. This will leave our plugin’s test classes with no access to fixtures, database.yml configuration, or any of those nice class auto-loading features.

Connecting to MSSQL with Ruby on Ubuntu - lambie.org

I’m working on a problem for a client which involves connecting to a Microsoft SQL Server 2005 database from Linux using Ruby. Here’s what I did to get it working, based off some useful instructions that are tailored for Ruby on Rails:

SourceForge.net: SWFRIP: Files

SWFRIP is a Macromedia Flash resource extractor and editor. It can save resources in various formats, including SVG conversion from the flash vector format, decompile ActionScript, and remove the protect tag from SWF files.

Google Summer of Code winner: ActiveModel for Ruby on Rails

Finish the remainder of the ActiveModel todo list (observers, callbacks, validations, scoping, and serialization) in addition to associations. Also wire up ActiveModel up to ActiveRecord and ActiveResource.

Record Filter - Replace named scopes with awesome.

Record Filter gives you the full power of ActiveRecord's query building tools with a heaping helping of DSL thrown in to save your Ruby-loving fingers from writing nasty SQL.

Page Speed Home

Page Speed is an open-source Firefox/Firebug Add-on. Webmasters and web developers can use Page Speed to evaluate the performance of their web pages and to get suggestions on how to improve them.

rubaidh's rubaidhstrano at master - GitHub

Capistrano recipes for database backups before migrations, passenger deployment strategy, release tagging in Git repos.

sdsykes's read_from_slave at master - GitHub

Read_from_slave for Rails enables database reads from a slave database, while writes continue to go to the master

HotKey : Programmable keyboard shortcuts for Prototype

HotKey provides functionality similar to the accesskey attribute, but has many enhancements that allow for more granular control when creating keyboard driven interfaces.

citrusbyte's contest at master - GitHub

Write declarative tests using nested contexts without performance penalties. Contest is less than 100 lines of code and gets the job done.

ActiveRecord Optimization with Scrooge - igvita.com

The idea behind scrooge is both surprisingly simple and powerful: instead of forcing the developer to manually specify each attribute column, simply observe and record for some period of time all of the attribute accesses and then reuse this knowledge in the future to automatically optimize your subsequent query requests.