Error installing the raspell gem
When you get this while installing the raspell gem:
ERROR: Error installing raspell:
ERROR: Failed to build gem native extension.
You need some libraries:
sudo apt-get install libaspell-dev
Aspell Error - No word lists can be found for the language XY
When you get this error:
No word lists can be found for the language "de".
An aspell dictionary is missing. Install it with
sudo apt-get install aspell-de
stefankroes's ancestry at master - GitHub
Ancestry is a gem/plugin that allows the records of a Ruby on Rails ActiveRecord model to be organised as a tree structure (or hierarchy). It uses a single, intuitively formatted database column, using a variation on the materialised path pattern. It exposes all the standard tree structure relations (ancestors, parent, root, children, siblings, descendants) and all of them can be fetched in a single sql query. Additional features are STI support, named_scopes, depth caching, depth constraints, easy migration from older plugins/gems, integrit...
Release gem; Deploy gem; Update a gem created with Jeweler
Until May 2011 our gems have been created with Jeweler, which is a helper library to package code into a gem. You know a gem was cut with Jeweler if you see the word jeweler
in a gem project's Rakefile
.
This note describes how to update a gem that was cut using Jeweler. Note that this can be traumatic the first time. It would be great to have an easier workflow for this. Jeweler is deprecated these days because you can
**now [cut gems more easily using Bundler](https://makandracards.com/makandra/1229-updat...
Better output for Cucumber
We built cucumber_spinner to have a progress bar for Cucumber features, which also outputs failing scenarios as soon as they fail.
Installation
gem install cucumber_spinner
Usage
cucumber --format CucumberSpinner::ProgressBarFormatter
If you use CucumberSpinner::CuriousProgressBarFormatter
and a feature fails, the according page will show up in your browser.
Note that if you run your Cucumber tests using the [cuc
](https://makandracards.com/makandra/1277-a-nicer-way-to-...
Test concurrent Ruby code
To test concurrent code, you will need to run multiple threads. Unfortunately, when you use blocking system calls (e.g. locks on the database), Ruby 1.8 threads won't work because system calls will block the whole interpreter.
Luckily you can use processes instead. fork
spins off a new process, IO.pipe
sends messages between processes, Process.exit!
kills the current process. You will need to take care of ActiveRecord database connections.
Here is a full-fledged example:
describe Lock, '.acquire' do
before :each do
...
Better Output for RSpec
rspec_spinner is a progress bar for RSpec which outputs failing examples as they happen (instead of all at the end).
Installation
gem install rspec_spinner
Usage
script/spec -r rspec_spinner -f RspecSpinner::Bar -c
To make a shortcut in your .bashrc
alias ss='script/spec -r rspec_spinner -f RspecSpinner::Bar -c'
There's also an alternate runner RSpecSpinner::Spinner
which shows a spinner and the name of the current spec instead of a progress bar.
Concurrent Tests
Install gem and plugin
sudo gem install parallel
script/plugin install git://github.com/grosser/parallel_tests.git
Adapt config/database.yml
test:
database: xxx_test<%= ENV['TEST_ENV_NUMBER'] %>
Create test databases
script/dbconsole -p
CREATE DATABASE `xxx_test2`;
...
Generate RSpec files
script/generate rspec
(you'll probably only let it overwrite files in script/
)
Prepare test databases...
Parse XML or HTML with Nokogiri
To parse XML-documents, I recommend the gem nokogiri.
A few hints:
-
xml = Nokogiri::XML("<list><item>foo</item><item>bar</item></list>")
parses an xml string. You can also callNokogiri::HTML
to be more liberal about accepting invalid XML. -
xml / 'list item'
returns all matching nodes;list item
is used like a CSS selector -
xml / './/list/item'
also returns all matching nodes, but.//list/item
is now an XPath selector- XPath seems to be triggered by a leading
.
...
- XPath seems to be triggered by a leading
Rails - Multi Language with Fast_Gettext
sudo gem install gettext --no-ri --no-rdoc
sudo gem install fast_gettext --no-ri --no-rdoc
-
script/plugin install git://github.com/grosser/gettext_i18n_rails.git
(didn't work as gem) - environment.rb: see code example at the bottom
-
if this is your first translation:
cp locale/app.pot locale/de/app.po
for every locale you want to use - use method "_" like
_('text')
in your rails code - run
rake gettext:find
to let GetText find all translations used - translate messages in 'locale/de/app.po' (leave msgstr blank and ms...
Automatically build sprites with Lemonade
How it works
See the lemonade descriptions.
Unfortunately, the gem has a few problems:
- it does not work with Sass2
- it always generates all sprites when the sass file changes, which is too slow for big projects
- it expects a folder structure quite different to our usual
All these problems are solved for us, in our own lemonade fork. This fork has since been merged to the original gem, maybe we can use t...
Using Passenger for development (with optional SSL)
- install apache
sudo apt-get install ruby1.8-dev
sudo gem install passenger
sudo passenger-install-apache2-module
- follow the instructions
Manually: configure a vhost in /etc/apache2/sites-available
and link it to /etc/apache2/sites-enabled
with something like the following
^
NameVirtualHost *:80
<VirtualHost *:80>
ServerName application.local
DocumentRoot /opt/application/public
RailsEnv development
RailsAllowModRewrite off
</VirtualHost>
<VirtualH...
Freeze (vendor, unpack) a single Ruby gem with and without Bundler
When you need to patch an existing gem, one way is to "vendor" the gem by copying it into the vendor/gems
directory of your Rails project. You can then make any changes you require and Rails will use the vendored version of the gem after a server restart. Unfortunately you need to perform some additional steps to marry Rails and the copied gem. This notes describes what to do.
With Bundler
This is super-painful. If you just copy the gem to vendor/gems
, Rails will complain:
Unpacked gem foolib in vendor/gems has no s...
How to install the date_performance gem
sudo gem install zip
git clone git://github.com/rtomayko/date-performance.git
cd date-performance
rake package:build
cd dist
sudo gem install --no-ri --no-rdoc date-performance-0.4.7.gem
Install a gem without RI and RDdoc
To improve installation times of gems you can use the following approach:
gem install xyz --no-document
To permanently ignore ri
and rdoc
when installing gems, add this line to ~/.gemrc
:
gem: --no-document
Be aware that eliding local documentation may disable documentation support in your IDE.
Create an application with an older Rails version
sudo gem install rails --version="=1.2.3"
rails _1.2.3_ new-project-folder
Run a single test in Test::Unit
To run a single test file:
rake test:units TEST=test/unit/post_test.rb
rake test:functionals TEST=test/functional/posts_controller_test.rb
rake test:integration TEST=test/integration/admin_news_posts_test.rb
You may even run a single test method:
ruby -I test test/unit/post_test.rb -n "name of the test"
ruby -I test test/functional/posts_controller_test.rb -n test_name_of_the_test # underscored, prefixed with 'test_'
Or all tests matching a regular expression:
ruby -I test test/integration/admin_news_posts_test.r...
Configuring Git with .gitconfig
Basic configuration
Please keep this config simple. It should be a starting point for new developers learning Git.
[user]
name = Your Name
email = your.name@domain.com
[branch]
sort = -committerdate
[color]
ui = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
whitespace = white reverse
meta = blue reverse
frag = blue reverse
old = red
new = green
[color "status"]
added = green
changed = yellow
untracked = cyan
[interactive]
singlekey = true # Do not requir...
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 ...
Cerberus: Home
Cerberus is a lightweight and easy-to-use Continuous Builder software for Ruby. It could be run periodically from a scheduler and check if application tests are broken. In case of failed tests Cerberus sends notification to developers.
Sanitize: A whitelist-based Ruby HTML sanitizer
Given a list of acceptable elements and attributes, Sanitize will remove all unacceptable HTML from a string.
It's an HTTParty and Everyone Is Invited! // RailsTips by John Nunemaker
Awesome library to consume web services in Ruby.