Posts Tagged “rails”
Posted by alex in Insights
I assisted in looking into a Rails issue earlier with a friend. After making some modifications to some Ruby code he had an issue receiving exception emails which were generated by Rails. The rails plugin being used to accomplish this is called exception_notification and resolving the problem was simple. As you will see below instead of upgrading the entire plugin a couple lines in one ruby file were modified, the web server restarted, and the exceptions again started functioning properly. Below I display more of the error and the modifications made to resolve the error.
Read the rest of this entry »
Tags: 2.1, ActionView, error, exception notification, exception_notification, exception_notifier_helper.rb, filter_parameters, plugin, production log, rails, Ruby, TemplateError
No Comments »
Posted by alex in Insights
The other day I did some optimization work on a PostgreSQL database and at the end needed to create migrations so the changes I was going to make could be deployed on multiple servers. It was my first shot at migrations so I wanted to note for myself and anyone else that may find it useful how to create Ruby migrations for dropping and adding Indexes on PostgreSQL tables. Below you will find the basic concept for creating a migration that adds a Postgres table index and information on removing a table index which is just the reverse of adding.
Generate And Run A Ruby Migration That Adds A Index To A PSQL Table:
- Generate Blank Migration: First you should generate a blank migration which will add a date timestamp to the beginning of the migration file name. The command below will generate a migration file with the name 20091223181025_index_postgre_sql_table.rb located in the db/migrate folder within your Ruby projects root directory.
Generate Blank Ruby Migration:
ruby script/generate migration IndexPostgreSQLTable
- Add PostgreSQL Index Using Migration File: Now open the newly created migration file in your favorite editor. Below is a view of the default migration file followed by the addition of adding one index to a single table in PostgreSQL.
Default Ruby Migration File:
class IndexPostgreSqlTable < ActiveRecord::Migration
def self.up
enddef self.down
end
end
The above displays what the default file will look like. It has two important sections to notice which is where you will be adding code. The self.up is the are you will add the ruby code for the index you want to generate and the self.down should be the reverse of this command so things can be rolled back. Below is an example of adding a single PostgreSQL index on the address and location fields to the servers table.
Added Ruby Code To Migration File To Generate An Index On A PostgreSQL Table:
class IndexPostgreSqlTable < ActiveRecord::Migration
def self.up
add_index :servers, [:address, :location]
end
def self.down
remove_index :servers, [:address, :location]
end
end
As you can see above the syntax is really simple for adding and removing indexes from PostgreSQL tables. If you wanted a migration that would remove an index simply swap the remove_index and add_index lines in the migration file.
- Run Migration: Once you are ready to test you need to run the migration using syntax similar to the below logged in as the owner of your Ruby project and from the Ruby projects root directory.
Run Migration Using Rake:
rake db:migrate RAILS_ENV="production"
If this is a development environment you may want to change the Rails environment from production to development but that will depend on how you have things set up.
If the migration is successful then check it into your file management system and it can easily be rolled out to all servers. The migrations will obviously need to be run on each server so the changes modify each separate database.
David Black. Manning Publications 2006, Paperback, 532 pages, $11.20

Dan Chak. O’Reilly Media 2008, Paperback, 325 pages, $25.68

Tags: development, index, migration, postgres, PostgreSQL, production, project, psql, rails, RAILS_ENV, rake, Ruby, self.down, self.up
No Comments »
Posted by alex in Insights
A friend of mine was over tonight and we were troubleshooting a issue with SVN authentication via the Redmine project management software. Redmine is built with Ruby and on this server is running via Apache and Mongrel. I needed to set the project to run in development mode but wasn’t very familiar with the Mongrel setup. After some research I found it was easy to change the environment from production to development using the Mongrel Cluster .yml file for that project. When using Mongrel each site appears to get its own .yml file so you can modify whatever settings you want to on a per site basis. Below I describe what needs to be changed, default locations, and any other actions that need to be taken to restart the Ruby on Rails project in development mode.
Read the rest of this entry »
Tags: .yml, apache, development, development.log, environment, mode, mongrel, mongrel_cluster, production, project, rails, Ruby, ruby on rails
No Comments »
Posted by alex in Insights
A friend of mine let me know about a vulnerability in Redmine today so I decided to upgrade to the latest stable release. Upgrading Redmine is easy but figured I would log the exact steps I took to upgrade from Redmine 0.8.3 to Redmine 0.8.7. The installation of Redmine I upgraded is running off of a MySQL database. Also the upgrade is easier since it was a minor version upgrade and didn’t require upgrading Rails, MySQL, or Ruby. The requirements for each Redmine version are located here in case you aren’t sure if you have the correct versions of Rails, Ruby, and MySQL installed.
Read the rest of this entry »
Tags: 0.8.3, 0.8.7, cp, files, mv, mysql, plugins, rails, redmine, requirements, Ruby, stuff to do, tar
No Comments »
When debugging Rails, I often open up an iRb shell by typing
[BASH]
ruby script/console
[/BASH]
This command lists all instance methods in the User model, excluding inherited methods and sorts them in alphabetical order.
[BASH]
User.instance_methods(false).sort
[/BASH]
I will add more useful iRb methods as I discover and remember them
Tags: console, instance methods, irb, methods, rails, shell
No Comments »
|