ActiveRecord OR query

If you want to use an OR operator on one column’s value, you can pass an array to .where and ActiveRecord will use IN(value,other_value): Model.where(:column => [“value”, “other_value”] outputs: SELECT `table_name`.* FROM `table_name` WHERE `table_name`.`column` IN (‘value’, ‘other_value’) This should achieve the equivalent of an OR on a single column

Best way to add page specific JavaScript in a Rails 3 app?

What I like to do is include the per-view Javascript in a content_for :head block and then yield to that block in your application layout. For example If it’s pretty short then: <% content_for :head do %> <script type=”text/javascript”> $(function() { $(‘user_rating_positve’).click(function() { $(‘some_div’).show(); } }); </script> <% end %> or, if longer, then: <% … Read more

Can’t find the ‘libpq-fe.h header when trying to install pg gem

It looks like in Ubuntu that header is part of the libpq-dev package (at least in the following Ubuntu versions: 11.04 (Natty Narwhal), 10.04 (Lucid Lynx), 11.10 (Oneiric Ocelot), 12.04 (Precise Pangolin), 14.04 (Trusty Tahr) and 18.04 (Bionic Beaver)): … /usr/include/postgresql/libpq-fe.h … So try installing libpq-dev or its equivalent for your OS: For Ubuntu/Debian systems: … Read more

Ignoring time zones altogether in Rails and PostgreSQL

Postgres has two different timestamp data types: timestamp with time zone, short name: timestamptz timestamp without time zone, short name: timestamp timestamptz is the preferred type in the date/time family, literally. It has typispreferred set in pg_type, which can be relevant: Generating time series between two dates in PostgreSQL Internal storage and epoch Internally, timestamps … Read more