Tag Archives: ruby on rails

Using render-anywhere gem with partials

Normally in rails, you can only render views inside of the controller. But what if you want to render a view somewhere else? For instance we wanted to generate xml-files using views. Haml can be used to describe xml just as well as plain html. There is a gem called render_anywhere that allows just that. […]

[rails] ignoring specific postgis view and tables in schema.rb

Developing rails websites with a geographic component we rely heavily on Postgis, so we use activerecord-postgis-adapter for the Postgis support, and I always use schema_plus because it allows me to define views. Until recently, I always had to use the structure.sql instead of the schema.rb because the geometric columns did not dump correctly. But for […]

[rails] select distinct values of a column

The simplest way to select all distinct values of a column is, somewhat unintuitively: Visit.uniq.pluck(:project) this runs the query select distinct project from visits, and returns an array of strings. Exactly what you need, except … I want it to be paginated. So we Visit.uniq.pluck(:project).page(1) … and that completely bombs: we now get an array […]

[rails 4] add a reference to a table with another name

They default way in rails 4 to add foreign keys is simply add_reference :people, :user And this will add a column user_id to the people table, if the table exists. I have been looking in the rails code where this is handled, and it is really straightforward. Note that standard rails does not really do […]

How to clean assets in rails 4

Gentle reminder, do not forget, in rails 4 rake assets:clean seems to work, but actually does nothing. That is not entirely true: it only cleans the old assets, leaving the three most recent versions of the assets intact. So it is a like a mild cleaning, a throw-away-the-garbage-clean, a bring-those-old-clothes-you-never-wear-to-the-thriftstore-clean. But sometimes that does not […]

Run rails 2.3.18 using ruby 1.8.7 on windows server 2012

For my current job we have two 2.3.5 rails sites, of which I already succesfully upgraded one to rails 4. For the other we still need to start the migration, and we were asked to install new windows servers to run the rails servers on in the meantime (let’s not digress why they choose windows, […]

complete coverage with SimpleCov

When using SimpleCov in a very ill-covered project, I got amazingly good results: SimpleCov just did not count not-covered files. So files that were never used in our test-suite, were just simply being ignored. While I understand that approach, it did not feel good. I want to measure absolute progress, and I want to know […]

[netzke] make action buttons toggle

I am currently converting my GIS application that needs two browser windows (one for the map, and one for the administrative data and functions), to a single window application using the netzke gems (which in turn rely on Sencha Ext js). The netzke gems are extremely powerful, but there is a bit of learning curve […]

generating pdf on heroku

I was investigating ways to generate pdf’s in Ruby on Rails, but I had one enormous constraint: it had to deploy on heroku. There are two very different ways to generate pdf’s in ruby: use prawn: it is pure ruby, very powerful. It has it’s own DSL, that unleaches all the power of building a […]

testing drag and drop of jQuery UI sortable with cucumber and capybara

The Problem For jottinx I wrote a small piece of code that allowed to sort items using drag and drop. Of course, after writing it and making sure it works (manually), I want to make sure it keeps working. So I add a test, using cucumber. My scenario actually looks pretty straightforward: The difficult bit […]