March 9, 2014

Bitnami Rubystack Virtual Host Configuration

I recently upgraded to a new version of Bitnami Rubystack, which upgraded Apache from 2.2 to 2.4.  Try as I may, I couldn’t get my virtual host to come up.  I finally traced this back to default virtual hosts being defined for in one of the bitnami configuration files.  So if you are fighting with this, comment out the reference to  Include “/opt/bitnami/apache2/conf/bitnami/bitnami.conf” at the bottom of the default httpd.conf file.

March 5, 2014

Rebuilding an Elasticsearch Index

So for the next time I forget this, here are the steps needed to rebuild and Elasticsearch Index using the Tire gem with ActiveRecord integration:

  • Klass.search_index.delete
  • Klass.create_elasticsearch_index
  • Klass.import

Where Klass is the name of the class you have defined the index on.

February 28, 2014

Installing ElasticSearch on Ubuntu

This worked great for me:

If you want elasticsearch to start on startup, be sure to follow the instructions that are given once the package is installed:

  • sudo update-rc.d elasticsearch defaults 95 10
  • sudo /etc/init.d/elasticsearch start
February 27, 2014

Rails 3.2 -> Rails 4.0 Upgrage

So some random notes around what I’ve run into.

First off, if you haven’t already, generate a new Rails 4 project, just so you have something to refer to/steal from.

Here are changes that I’ve had to make

Gemfile

  • Specify rails 4.0 - gem ‘rails’, ‘~> 4.0.0’
  • Get rid of assets block - I’ve been replacing it with the following:

gem ‘sass-rails’,   ‘~> 4.0.0’
gem ‘coffee-rails’, ‘~> 4.0.0’
gem ‘uglifier’, ‘>= 1.3.0’

Scripts

  • Rails 4 has moved the location of the rails script from /scripts to /bin.  I generated a blank Rails 4 project, and copied the /bin directory over.

application.rb

  • Remove the ‘require “active_resource/railtie” ’ line
  • Reduce the bundler block down to simply ‘Bundler.require(:default, Rails.env)’

environments

  • Get rid of config.whiny_nils
  • Set config.eager_load according to the warning you will get when you start the rails server

routes.rb

  • Change all your match calls to get/post calls

That pretty much did it for getting the application up and running for me.  Of course, after that, you have to start dealing all the other changed and depreciated features.  Be sure to be watching your development server log, as it does a good job at telling you what to dig into.

February 14, 2014

Rails 4 - Custom Fonts - One more Thing

Missed one step in my previous post.  It appears that when you precompile your assets, you need to specify your rails environment, or the results will be, shall we say, ‘inconsistent’.  Use the following command to precompile your assets:

 RAILS_ENV=production rake assets:precompile

Also, if you are getting flakiness, kill off the contents of the public/assets folder, forcing everything to recompile.

Rails 4 SCSS font-path Helper

I ran into a problem with a custom font that I was using, in that while the asset pipeline was adding the hash to the name of the font files, it was not adding it in the font-face definition in the generated CSS file, and thus I was getting 404 while trying to download the fonts into the browser, and no pretty icons on my page.  After a couple of hours of thrashing about, I finally found the solution.  As it turns out, I had the font-face definition in a file that I included into another file.  Moving the font-face definition into the master scss file fixed the problem.  It appears that there is some issue with font-path not generating the correct url from an includes.

Rails 4 Asset Pipeline

Ran into a problem deploying my application to production - not all my CSS files were getting compiled when I did a assets:precompile.  I use a couple of page type specific manifest files.  I had added these into my config.assets.precompile in the production.rb, but it was being ignored.  After finding this issue: https://github.com/rails/sprockets-rails/pull/36, I moved the config.assets.precompile to the application.rb, and life got better.

February 12, 2014

Rails 4 Circular Dependency

I ran into a problem updating a Rails 3.2 app to Rails 4.0.  I was getting a circular dependency error while loading the ReportsController.  After Googling about a bit, I started throwing some $hit at the wall, and came up with the problem.  I had a concern called ReportsHelper which I renamed to ReportsUtil, and that fixed the problem.  It appears that Rails was finding what it thought was a Helper and loading it into the controller, and then reloading it again…

What is a bit strange is I took the ‘include Concerns::ReportsHelper’ out of the controller, and it didn’t change behavior at all - even after restarting the server.  So looks like Rails magic was biting me; at least it didn’t to long to figure it out…

create_table options not copied over to schema.rb

Had a bit of a surprise when I did a db:test:prepare - none of my tables ended up in the proper tablespaces.  Upon further investigation, it appears that the options: settings from migrations create_table are not copied over into the schema.rb file.  While not a big deal for testing, in production this would turn into a problem if you bootstrap your database using db:schema:load.

Rails Migrations - Specifying Tablespace

If you are getting all fancy and using multiple tablespaces in your database,  Rails makes it nice and easy to specify the tablespace a database or table is supposed to go in (at least for Postgres…).

At the database level, in your database.yml, you can just add a tablespace: name line n your database definition:

development:
  adapter: postgresql
  encoding: unicode
  database: ngn1_development
  tablespace: ngn1_data

To assign individual tables to different tablespaces, simply add an options: setting to the create_table statement:

create_table :session_logs, :id=>false, options: ‘TABLESPACE ngn1_log’ do |t|….

These all assume you have already created your tablespaces.  I did this outside of rails migrations, as the database user that I use for my Rails connection does not have the authority to create tablespaces.