Advice for address forms that work with address structures from multiple countries.
When you build a link for an email body like this
body = "Please click the following link"
body << "http://posts/130\n\n"
body << "Members:"
then updating Spreewald to >=0.6.7 will be able to parse it correctly.
It is good programming practice to Don't Repeat Yourself (or DRY). In Ruby on Rails we keep our code DRY by sharing behavior by using inheritance, modules, traits or partials.
When you reuse behavior you want to reuse tests as well. You are probably already reusing examples in unit tests. Unfortunately it is much harder to reuse code when writing integration tests with Cucumber, where you need t…
So you client has asked you to implement a row of buttons to like the URL on Facebook, Twitter and Google+. Here are some things you should know about this.
Chrome extension that shows all info from your rails log (like parameters, response times, view rendering times, DB requests) inside a chrome panel.
When writing Rails migrations to convert a
string column to an
integer you'd usually say:
change_column :table_name, :column_name, :integer
However, PostgreSQL will complain:
PG::DatatypeMismatch: ERROR: column "column_name" cannot be cast automatically to type integer HINT: Specify a USING expression to perform the conversion.
The "hint" basically tells you that you need to confirm you want this to happen, and how data shall be converted. Just say this in your migration:
change_column :table_name, :column_name, 'i...
One of many useful techniques when your test suite needs to talk to a remote API.
Geordi 0.16+ supports running selenium tests with project-specific firefox versions.
Just update the gem. It will still default to using the old 5.0.1 firefox. If you want another one, add a file
.firefox-version to your project, containing your preferred version.
geordi cucumber will prompt (and guide) you to install the given version. You can delete any old installation sitting in
/opt/firefox-for-selenium if you have one.
If you want to have routes that are only available in tests (e.g. for testing obscure redirects), you can use the
with_routing helper – but that one destroys existing routes which may break a specs that require them to work.
To keep both "regular" and test routes, do this:
class MyApplicationController < ActionController::Base def show render text: 'Welcome to my application' end end test_routes = Proc.new do get '/my_application' => 'my_application#show' end Rails.application.routes.ev...
I recently experienced the error
ActiveRecord::StatementInvalid: Mysql2::Error: closed MySQL connection. Apparently this happens when there is a timeout during query execution. In order to fix this you can reconnect to your db.
Therefore either add
reconnect: true to your database.yml for automatic reconnection when the error occurs or catch the error and manually and reconnect explicitly via
Be aware that reconnecting will have the following impact on your current connection:
If you need to enable NewRelic monitoring on certain machines within the same Rails environment, a simple solution is to utilize the respective hostnames of you machines.
For example, if you have 8 application servers (e.g.
app2.example.com, …) and want to enable NewRelic on
app2 only, utilize those steps to do so:
NEWRELIC_HOSTSconstant and list …
You're better off using
gem install debugger-ruby_core_source
If you can't do this, try the following.
Here is how to fix the following error when installing the
debugger gem fails:
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension
Note: The following example is for a project using Ruby 1.9.3-p448 – adjust accordingly for your project.
Fetch the source for your Ruby version, if you do not yet have it:
rvm fetch ruby-1.9.3-p448
Establishing a new SSH connection usually takes only a few seconds, but if you’re connecting to a server multiple times in succession the overhead starts to add up. If you do a lot of Git pushing and pulling or frequently need to SSH to a dev server, you’ve probably felt the pain of waiting for SSH to connect so you can get back to doing work.
Copy the attached file to
features/support. This gets you a convenience method:
true for Selenium, capybara-webkit, Poltergeist and a custom driver called
:chrome (which we sometimes like to use for Selenium+Chrome).
A practical guide.
There may be reasons to change the locale of your Postgres cluster. A popular one is your development system's locale being used by default (which may be annoying). Here is how to do that.
Beware: By following the steps below, you will drop and recreate your cluster. You will lose all data (including roles). Instructions below include a procedure for dumping and restoring all cluster data (including roles). While it worked at the time of writing, you should have extra backup strategies for a production database.