Tag: rails
-
Resetting password of Devise user from the database
I recently encountered a situation where I was trying to access a Rails application but: I didn’t know the password for the admin user The reset password functionality was not working I had no access to a Rails console Knowing the User model was using Devise, I set a password for a user on a…
-
Get database version in Rails
For one of my applications, I recently created a status report page which shows crucial information for debugging, including software versions, service connectivity and filesystem path writability. One of the items was a database version string, and the standard ActiveRecord interface does not support this concept. While version methods usually exist in the connection adapters,…
-
Optimising index view performance
I recently came across a scenario where my index views in Rails were taking a long time to render when there were large data sets. The problem stemmed having a lot of data presented that were from models/tables other than the primary model/table of interest. For example, an “asset” index view may have the following…
-
Apache2 configuration for Rails
I recently had to stand up a Rails production server that used Apache2 as a reverse proxy. While it was relatively easy proxying requests to the Thin server using ProxyPass, assets would not show up, even with a DocumentRoot specified. It seems that ProxyPass proxies all requests, and the configuration needs to specifically ignore proxying…
-
Selecting string literals in Rails 4 using PostgreSQL
I recently ran into an issue with Rails 4 using the PostgreSQL adapter (MRI) where selecting a string literal in a query would return a warning about an unknown OID. This can be reproduced by running the following in Rails Console: This occurs both with and without column aliases. 705 is PostgreSQL’s code for an…
-
Using Rails’ descendants in development
Rails provides a nice method descendants that returns all subclasses for a specified class. However, config.cache_classes = false is a default setting in development.rb (for the ability to reload classes on the fly) and as this tells Rails not to load classes until they are referenced, then calling descendants will generally return an empty array…
-
Reducing Rails asset precompile times on JRuby
Rails asset precompile times on JRuby are considerably slower compared to MRI. I came across this post which provided suggestions on speeding up the asset precompile task. Using the following options – using Node.js instead of therubyrhino for JS compilation, forcing the JVM to 32 bit (although this can be omitted on a 32 bit…