View

Advantages of using appname.vcap.me:3000 over localhost:3000

Running rails server will start a local server that you can access via http://localhost:3000.

When you are working on multiple web apps, they will all set cookies on localhost. This is annoying, since you will sign out your current user whenever you switch to another app.

A better way is to use the vcap.me service. All vcap.me subdomains resolve to your local IP (127.0.0.1). That means you can use a different hostname for different apps, and you will stay logged in in each app:

```text
http://foo-app.vcap.me:3000 => 127.0.0.1
http:/…

Auto-destruct in 57 days

Updated: Using Rails with Webpack: First steps

Caveat: If your yarn.lock changes (e.g. you checkout a previous commit or a commit from a colleague) you need to run manually yarn and restart you webpack-dev-server. Otherwise the outdated versions in your node_modules folder are used.

Note yet solved

Changing the version of a package and restarting the webpack-dev-server does not affect the test. The test still uses outdated files from public/packs-test. Removing the folder manually triggers the tests to recompile the assets. I don't now how to do this manually.

This is t…

Repeats

Heads up: Focus-sensitive Selenium tests do not work reliably in parallel test execution

Firefox will not trigger focus/blur events when its window is not focused. While this makes sense in standard usage, it breaks in parallel test execution.

Please do not rely on focus events in your tests. The linked card has an example of how to build passing tests that deal with focus/blur events.

HTML5: disabled vs. readonly form fields

Form fields can be rendered as noneditable by setting the disabled or the readonly attribute. Be aware of the differences:

disabled fields

  • don’t post to the server
  • don’t get focus
  • are skipped while tab navigation
  • available for button, fieldset, input, select, textarea, command, keygen, optgroup, option

Browser specific behavior:

  • IE 11: text inputs that are descendants of a disabled fieldset appear disabled but the user can still interact with them
  • Firefox: selecting text in a disabled text field is no…

Fixing PostgreSQL PG::InsufficientPrivilege error

DatabaseCleaner needs to disable foreign key constraints before it can wipe the database. To do so, the application's PostgreSQL user must be a superuser. Grant superuser rights like this:

$ sudo -u postgres psql
# ALTER USER <your username> WITH SUPERUSER;

How to: Restart vnc server for geordi

Trying to open a vnc window with geordi geordi vnc ended up with this error:

> VNC viewer could not be opened:
vncviewer: ConnectToTcpAddr: connect: Connection refused

Check if vncserver 17 (default geordi session) is running:

ps -aux|grep vnc

If you see Xvnc4 :17 then the server is already running. Kill this server if it is already running.

vncserver -kill :17

No…

VNC browser disappears while typing

We often use the Then console step from spreewald in combination with geordi vnc from geordi to debug tests within a real browser. Sometimes when you type in the browser it suddenly disappears. You will only see a grey screen then.

This will always happen if you press the d key. Press the d key again and the browser will appear again.

Repeats

custom maintenance page

Add a custom maintenance page for each vhost (require capistrano 3.x):

Installation

Add this line to your application's Gemfile:

gem 'capistrano', '~> 3.0'
gem 'capistrano-maintenance', '~> 1.0'

Add this line to you application's Capfile:

require 'capistrano/maintenance'

Enable task

Present a maintenance page to visitors. Disables your application's web interface by writing a #{maintenance_basename}.html file to each web server. The servers must be configured to detect the presence of this file, and if it i…

Auto-destruct in 55 days

Unpoly 0.53.0 and 0.52.0 released

0.53.0

New module: Passive updates

Thi work-in-progress package up.radio will contain functionality to passively receive updates from the server. Currently the following functionality is implemented:

  • Elements with an [up-hungry] attribute are updated whenever there is a matching element found in a successful response. The element is replaced even when it isn't targeted directly.

    Use cases fo…

Repeats

Calling a helper method with the same name as your current partial

Partials always define a local variable with the same name as themselves. E.g. when you are in _recent_users.html.erb, a local variable recent_users will be defined and overshadow any helper method that is also called recent_users().

If you would like to use a helper method recent_users() in a partial _recent_users.html.erb you can say this in the partial template:

<% recent_users = self.recent_users %>
<% recent_users.each do |user| %>
  ...
<% end %>
Auto-destruct in 47 days

Updated: Dealing with I18n::InvalidPluralizationData errors

Added
- debug instructions
- quick explanation
- more background

Mysql::Error: BLOB/TEXT column can't have a default value

mysql> SELECT @@global.version;
+------------------+
| @@global.version |
+------------------+
| 5.6.30           |
+------------------+
1 row in set (0,00 sec)

MySQL 5.6 Reference Manual says "BLOB and TEXT columns cannot have DEFAULT values".

If you want to run migrations in development here are two variants which might help. If you are not sure about the side effects (e.g. your application is broken when it doesn't set additional default values on application side, too…

Repeats

How to run a small web server (one-liner)

Sometimes you just want to have a small web server that serves files to test something.

Serve the current directory

On Ruby 1.9.2+ you can do the following ("." for current directory).

ruby -run -ehttpd . -p8000

Python 2.x offers a similar way.

python -m SimpleHTTPServer 8000 .

This is the same way with Python 3.x

python -m http.server

In both cases your web server is single-threaded and will block when large files are being downloaded from you.

For solutions in many other languages, see the [big list of http s…

Nested Spreewald patiently blocks are now patient

In Spreewald 1.10.4+, nested patiently blocks are now patient. That means when you nest multiple patiently blocks, each will block will wait the full time for the code it guards, ignoring time that is spend in nested patiently blocks.

Here is an example:

patiently do
  outer_code
  patiently do
    inner_code_taking_1s
  end
end

If your default wait time is 5 seconds, and the inner code takes 1 second, the outer patiently will wait for up to 6 seconds (5 + 1) for its block to complete.

In earlier versions of Spreewald…

Repeats

Don't name columns like counter_cache columns

ActiveRecord has a feature called counter caching where the containing record in a has_many relationship caches the number of its children. E.g. when you have House has_many :rooms, Rails can cache the number of rooms in House#rooms_count.

Mind that when a model has a column that looks to Rails like a counter-cache column, Rails will apply counter-cache logic to your model, even if you're not using counter caches.

E.g. you have a house with 12 rooms, but `house.r…

How to: Fix incorrect MySQL client library version

Bundler::GemRequireError: There was an error while trying to load the gem 'mysql2'.
Gem Load Error is: Incorrect MySQL client library version! This gem was compiled for 5.5.46 but the client library is 5.6.30.

Same as in Fix "libmysqlclient.so.20: cannot open shared object file: No such file or directory":

gem pristine mysql2

How to: Solve gem loaded specs mutex

Use bundler > 1.15 to fix Gem::LOADED_SPECS_MUTEX (NameError).


Given the following project:

ruby -v
ruby 1.8.7

bundler -v
Bundler version 1.13.7

gem -v
1.8.30

rails -v
Rails 3.2.22.1

Running specs or features resulted in:

uninitialized constant Gem::LOADED_SPECS_MUTEX (NameError)

The previous settings described in Maximum version of Rubygems and Bundler for Ruby 1.8.7 and Rails 2.3 (even the rails version was rails 3.2 and not 2.3) seems not to work here, so I used (also described in the ca…

View
3434 cards