Today, I ran into trouble on a fairly fresh installed VM, running Ubuntu. I tried to bundle install
and got this stacktrace:
Fetching gem metadata from https://rubygems.org/.Unfortunately, a fatal error has occurred. Please see the Bundler
troubleshooting documentation at http://bit.ly/bundler-issues. Thanks!
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require': no such file to load -- net/https (LoadError)
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from /usr/li...
If you want to install rabbitmq plugins on Ubuntu 12.04 you can do this with:
/usr/lib/rabbitmq/lib/rabbitmq_server-2.7.1/sbin/rabbitmq-plugins
This binary is not in your default $PATH. Beause of this you have to give the full path.
Check if you have puppetsync enabled on the master and client
[main]
logdir=/var/log/puppet
vardir=/var/lib/puppet
ssldir=/var/lib/puppet/ssl
rundir=/var/run/puppet
factpath=$vardir/lib/facter
templatedir=$confdir/templates
pluginsync = true
Check in /var/lib/puppet/lib
there should be a [...].rb somewhere. Delete it and look if it get copied again after with the next puppet run.
If you are using environments make sure the puppetmaster is also in the correct environment. (d...
In a nutshell: Capybara's find
will not work properly on nodes from a list. Don't find
on elements from a list.
Consider this HTML:
<div class="message">
<h2>Hello World</h2>
Lorem ipsum...
</div>
<div class="message">
<h2>Hello Universe</h2>
Lorem ipsum...
</div>
Now let's say you obtain a list of all such message
containers as an array:
messages = page.all('.message')
And then you look at their titles like this:
messages[0].find('h2').text
=> "Hello W...
Note that this seems to affect only recent Rails 2 versions.
You will not encounter this until you are writing to the cookie more than once, but when doing so, integration tests (Cucumber) may break for you with this error:
You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[] (NoMethodError)
The regular/short cucumber backtrace is not of any help but looking at the full trace reveals that ActionPack's `actio...
This script loads a dump into your development database.
You can provide the full path to you database dump like this:
load-dump path/to/my.dump
When you call load-dump
without any arguments it will show a menu with all dumps in your ~/dumps/
folder.
load-dump
This script is part of our geordi gem on github.
When using the asset pipeline your assets (images, javascripts, stylesheets, fonts) live in folders inside app
:
app/assets/fonts
app/assets/images
app/assets/javascripts
app/assets/stylesheets
With the asset pipeline, you can use the full power of Ruby to generate assets. E.g. you can have ERB tags in your Javascript. Or you can have an ERB template which generates Haml which generates HTML. You can chain as many preprocessors as you want.
When you deploy, Rails runs assets:precompile
...
Myth #5 (Each HTTPS Site Needs its Own Public IP Address) is actually still true, but the rest of the article is worth reading.
Geoffrey Grosenbach has created Gruff for easily plotting graphs. It is written in pure Ruby and integrates with Rails applications.
It provides features as automatic sizing of dots and lines (the more values, the thinner the graph's elements), custom or predefined themes, different styles (bar, line, dot and many more) and multiple graphs in one chart.
In your Gemfile:
gem 'rmagick', :require => false
gem 'gruff'
Then run bundle install
(and don't forget to restart your development server.)
This i...
Localizing a non-trivial application can be a huge undertaking. This card will give you an overview over the many components that are affected.
When you are asked to give an estimate for the effort involved, go through the list below and check which points are covered by your requirements. Work with a developer who has done a full-app localization before and assign an hour estimate to each of these points.
app
must be translated: Screens, mailer templates, PDF templates, helpe...Note: You might also want to check out BoxCryptor which does pretty much the same, and is supported across many more platforms. I just didn't want to use Dropbox...
I use Ubuntu One to automatically sync confidential files between my machines. The encryption is done via encfs, which is a file-based encryption that simply puts encrypted versions of files from one folder into another. This is well-suited for cloud storage, since it allows syncing single files, not whole crypt containers.
I'll ass...
TL;DR
%p
#{link_to "label", "url"}!
Haml is a great engine for writing shorter, readable HTML. However, there is one thing that troubles me regularly. Consider this Haml code:
%p
Visit our homepage at
= link_to "www.makandra.com", "http://www.makandra.com"
!
Haml will insert a space around the generated link, the result is this (see the space before the exclamation mark!):
<p>
Visit our website at <a href="http://www.makandra.com">www.makandra.com</a> !
</p>
They suggest to us...
When requests arrive at the application servers simultaneously, weird things can happen. Sometimes, this can also happen if a user double-clicks on a button, for example.
This often leads to problems, as two object instances are modified in parallel maybe by different code and one of the requests writes the results to the database.
In case you want to make sure that only one of the requests "wins", i.e. one of the requests is fully executed and completed while the other one at least has to wait for the first request to be completed, you ha...
Today, this line made me trouble. Can you spot the mistake?
match 'sitemap.xml' => 'feeds#sitemap', :constraints => { :format => 'xml' }, :as => 'sitemap'
The mistake is to match sitemap.xml
. Rails will by default strip any dot-anything, remember it as desired format and forward the rest of the request to the routing engine. Since we're making .xml
part of the match, it is not available for format determination and Rails will set the format to html
.
Unfortunately, the constraint won't complain in this case and Rails even ren...
How to call routes, make requests and try out helpers from the Rails console.
Sometimes you need a special version of chrome because it has some features you need for testing, like in this card. You do not need to use that Version apart from tests, because you can tweek selenium to use a special version that you set in your environment:
# features/support/chrome.rb
require "selenium/webdriver"
Capybara.register_driver :chrome320x480 do |app|
if driver_path = ENV["CHROME_SELENIUM_BIN...
When you want to test how an web-application reacts in a specific resolution, you can set up a specific Selenium driver for some tests:
Before('@chrome320x480') do
Capybara.current_driver = :chrome320x480
end
After('@chrome320x480') do
Capybara.use_default_driver
end
You can use either chromium or chrome beta (as of 2012.05 the Version "19.0.1084.41 beta" works), or any other member of the family. It only needs to supports the "--window-size" command-line switch. [See this list](http://peter.sh...
Controller responses often include Javascript code that contains values from Ruby variables. E.g. you want to call a Javascript function foo(...)
with the argument stored in the Ruby variable @foo
. You can do this by using ERB tags (<%= ruby_expression %>
) or, in Haml, interpolation syntax (#{ruby_expression}
).
In any case you will take care of proper quoting and escaping of quotes, line feeds, etc. A convenient way to do this is to use Object#json
, which is defined for Ruby strings, numb...
By default, Google Analytics tracks the current URL for every request. Sometimes you will want to track another URL instead, for example:
Luckily the Analytics code snippet allows you to freely choose what path is being tracked. Simple change this:
ga('send', 'pageview');
......
After installing Bundler 1.1 you will get the following warning when running tests:
WARNING: Cucumber-rails required outside of env.rb. The rest of loading is being defered until env.rb is called.\
To avoid this warning, move 'gem cucumber-rails' under only group :test in your Gemfile
The warning is misleading because it has nothing to do with moving cucumber-rails
into a :test
group. Instead you need to change your Gemfile
to say:
gem 'cucumber-rails', :require => false
You won't usually have to do this. It's OK to route all formats to a controller, and let the controller decide to which format it wants to respond.
Should you for some reason want to define a route that only responds to a given format, here is how you do it:
match 'sitemap.xml' => 'feeds#sitemap', :constraints => { :format => 'xml' }, :as => 'sitemap'
map.sitemap 'sitemap.xml', :controller => 'feeds', :action => 'sitemap', :format => 'xml'
When you regularly make use of Cucumber's "show me the page" step (or let pages pop up as errors occur), the capybara-20120326132013.html
files will clutter up your Rails root directory.
To tell Capybara where it should save those files instead, put this into features/support/env.rb
:
Capybara.save_and_open_page_path = 'tmp/capybara'
I followed this nice guide Connecting to MSSQL with Ruby on Ubuntu - lambie.org until I ran in the following errors:
irb(main):001:0> require "dbi"; dbh = DBI.connect('dbi:ODBC:MyLegacyServer', 'my_name', 'my_password')
DBI::DatabaseError: INTERN (0) [RubyODBC]Cannot allocate SQLHENV
from /usr/lib/ruby/1.8/dbd/odbc/driver.rb:36:in `connect'
from /usr/lib/ruby/1.8/dbi/handles/driver.rb:33:in `connect'
from /usr/lib/ruby...