So far, it\’s RoR

Ruby on Rails, PostgreSQL, SVN, etc….

Moved to http://www.question-defense.com

Posted by Chirag Patel on February 11, 2009

I’ve deciced to join forces with http://www.question-defense.com but will keep this blog up so I don’t break any links. All the posts in this blog have been copied to http://www.question-defense.com

Posted in Uncategorized | Leave a Comment »

Rails log analyzers

Posted by Chirag Patel on October 15, 2008

Here are the ones I tried. Hope the comments aren’t too confusing

  1. Simple Rails Log Query Analyzer
    • Ran ruby bin/query_log_analyzer.rb ../log/production.log
      • production.log.1 (small log file ~25MB) Just printed the “Totals” heading with no results
      • production.log (large log file ~400MB) Ran for a long time and nothing happened
  2. The Action Profiler lets you profile actions to determine points of optimization.
    • See attachment for the error when running action_profiler ChartController#index
    • Madhu thinks it requires Production Log Analyzer (which requires SyslogLogger)
  3. rawk.rb
    (recommended by Railscast.com)

    • production.log.1 (small log file ~25MB) shows 21,300 requests

    • production.log (large log file ~400MB) —shows only 27,200 requests
    • Both took about a miute to scan and since only 7,000 difference in requests, we think Rawk is not working
    • 07/23/08: Tried ruby rawk.rb ../log/production.log on sdev but hung for long time and never returned
  4. Hodel3000CompliantLogger
    • Looks like it’s working but requires mongrel_rails start instead of ruby script/server. Cannot use it easily with Litespeed probably.
    • Uses Production Log Analyzer but circumvents SyslogLogger (unlke Action Profiler above)
  5. Railscast.com’s Request Profiling

Posted in Uncategorized | 2 Comments »

View for version numbers, host names, IPs, etc

Posted by Chirag Patel on July 26, 2008

Here’s some code (and rendered view) for various version numbers, host names, IPs for Ruby, Rails, PostgreSQL, SMTP.


<b>Network</b><br>
UNIX hostname: <code><%= `hostname` %></code><br>
SERVER_ADDR: <code><%= request.env[“SERVER_ADDR”].to_s %></code> <br>
HOST_NAME : <code><%= request.host %></code> <br>
REMOTE_ADDR: <code><%= request.env[“REMOTE_ADDR”].to_s %></code> <br>
<br>
<b>Software</b><br>
Database: <code><%= ActiveRecord::Base.connection.select_value(“SELECT  VERSION()”) %></code><br>
Email delivery method: <code><%= ActionMailer::Base.delivery_method %></code><br>
SMTP server: <code> <%= ActionMailer::Base.smtp_settings[:address] %></code><br>
Ruby: <code> <%= “#{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) on #{RUBY_PLATFORM}” %> </code><br>
Rails: <code> <%= “#{Rails::VERSION::STRING}” %> </code><br>

Network
UNIX hostname: server1.mydomain.com
SERVER_ADDR: 10.2.128.100
HOST_NAME : www.mydomain.com
REMOTE_ADDR: 12.207.103.224

Software
Database: PostgreSQL 8.3.3 on x86_64-redhat-linux-gnu, compiled by GCC gcc (GCC) 4.1.2 20070626 (Red Hat 4.1.2-14)
Email delivery method: activerecord
SMTP server: localhost
Ruby: 1.8.6 (2007-03-13) on x86_64-linux
Rails: 2.1.0

Posted in Uncategorized | Leave a Comment »

Using helpers in models, views, and controllers

Posted by Chirag Patel on July 8, 2008

Using this as a guide JLHPBv2: Using Helpers in Models in Rails, you can make a single Module that can be accessed from models, views, and controllers. The helpers automatically created in app/helpers/*_helpers.rb   might also be available anywhere as long as you include them.

I decided to make the methods in the helper class-scoped (using self below) so that the origin of the helper method is explicitly obvious in the call (eg. to_s below)

app/lib/utility_helper.rb
module UtilityHelper
  def self.camelcase_to_spaced(word)
    word.gsub(/([A-Z])/, " \\1").strip
  end
end

app/models/event.rb
class Event < ActiveRecord::Base
  include UtilityHelper
 
  def to_s
    UtilityHelper.camelcase_to_spaced("This an Event object")
  end
end

app/helpers/events_helper.rb
module EventsHelper
  include UtilityHelper
end

app/controllers/event_controller.rb
class EventController < ApplicationController
  include UtilityHelper
end


app/views/events/index.html.erb
<%=UtilityHelper.camelcase_to_spaced(event[:event_type])%&rt;

Posted in Ruby on Rails, Uncategorized | 2 Comments »

FiveRuns TuneUp Rails Monitoring

Posted by Chirag Patel on June 19, 2008

I just installed FiveRuns TuneUp it’s great! A small header shows up on all your apps (see attachment). I run it locally only

It’s drop dead easy to install:

  • To add TuneUp to your Rails application, install the gem:

sudo gem install fiveruns_tuneup

  • Then, for a Rails 2.0.x app, run:

fiveruns_tuneup /path/to/rails/app

  • For a Rails 2.1 app, update your environment.rb to include this line:

config.gem ‘fiveruns_tuneup’

  • Launch your Rails app and you’ll see the header to sign up for for a free account view the stats.

Posted in Ruby on Rails | Leave a Comment »

Rails vs PHP vs Java vs …

Posted by Chirag Patel on January 23, 2008

Good sites comparing Ruby on Rails with other frameworks

 

Java to Rails:

Evaluation: moving from Java to Ruby on Rails for the CenterNet rewrite

 

PHP to Rails:

outside.in » outside.in switches to Rails

 

To be continuted….

Posted in Ruby on Rails | Leave a Comment »

User profiles with restful_authentication

Posted by Chirag Patel on December 22, 2007

 

Error when updating the user from a form

ActiveRecord::RecordInvalid (Validation failed: Password confirmation can’t be blank, Password is too short (minimum is 4 characters), Password can’t be blank):

 

 

 

Suggestion

It’s probably because of the restrictions on the User model (attr_accessible or attr_protected, in particular). But allowing users access to any part of the User model via mass assignment is dangerous. That’s why many people create a separate Profile model and link it via a 1:1 (belongs_to, has_one) relationship.

 

 

Solution

Coming soon

 

 

Posted in Ruby on Rails | 2 Comments »

Linux commands to install ImageMagick and RMagick

Posted by Chirag Patel on December 19, 2007

This is what I had to do to get it to work on CentOS 5. For some reason, FreeType would not work with yum so I built it from scratch. I’m not sure if the all the “yum install”s were needed, but I did it anyway.

#yum install freetype — did not work

cd /usr/local/src

wget http://download.savannah.gnu.org/releases/freetype/freetype-2.3.5.tar.gz

tar xvzf freetype-2.3.5.tar.gz

./configure

make

make install

 

yum install glib
yum install glib2
yum install libpng
yum install libjpeg
yum install libtiff
yum install ghostscript
yum install freetype

 

cd /usr/local/src

wget http://image_magick.veidrodis.com/image_magick/ImageMagick.tar.gz

tar xvzf ImageMagick.tar.gz

cd ImageMagick-X.Y.Z

./configure –disable-static –with-modules –without-perl –without-magick-plus-plus –with-quantum-depth=8 CFLAGS=-fPIC

make

make install

 

wget http://files.rubyforge.mmmultiworks.com/rmagick/RMagick-1.15.11.tar.gz

tar zxvf RMagick-1.15.11.tar.gz

cd RMagick-1.15.4

./configure

export LD_LIBRARY_PATH=/usr/local/lib

echo $LD_LIBRARY_PATH

make

make install

 

 

#test Rmagick in Rails

root# ruby script/console

irb(main):001:0> require ‘RMagick’

irb(main):002:0> include Magick

=> Object

irb(main):003:0> img = ImageList.new “test.jpg”

=> [test.jpg JPEG 10×11 DirectClass 8-bit 391b]

irb(main):004:0> img.write “test.png”

=> [test.jpg=>test.png JPEG 10×11 DirectClass 8-bit]

irb(main):005:0>

 

Posted in Linux, Ruby on Rails | Leave a Comment »

“Multiple default values” migration error with PostgreSQL 8.2.5

Posted by Chirag Patel on December 16, 2007

PostgreSQL 8.2.5 error

== CreateHeartrates: migrating ================================================

— create_table(:heartrates)

NOTICE: CREATE TABLE will create implicit sequence “heartrates_id_seq” for serial column “heartrates.id”

rake aborted!

PGError: ERROR: multiple default values specified for column “id” of table “heartrates”

: CREATE TABLE heartrates (“id” serial primary key DEFAULT NULL, “user_id” integer DEFAULT NULL, “timestamp” timestamp with time zone DEFAULT NULL, “heartrate” smallint NOT NULL)

 

 

Solution

I don’t see the above error on my Lenovo Windows machine because it’s running PostgreSQL 8.2.4. The issue occurs with PostgreSQL 8.2.5

 

Add this to the create table migration

 

t.column :id, :primary_key, :null => false

 

 

This is probably the simplest way to deal with this defect.

 

 

Post from: Migrations and PostgreSQL Primary Keys) – Rails Trac – Trac:

I tried to find a good place to patch the code, but everywhere I did, I could easily imagine someone yelling, “you can’t touch that”!

 

For instance, if scheme_definitions.rb’s primary_key could set :null => false, then everyone should be happy, even other db’s. Except, that of course you change all db’s to ‘NOT NULL’ versus ‘DEFAULT NULL’. I don’t know why you’d want to say ‘DEFAULT NULL’ though, it seems vaguely wrong.

 

This seems to be still in rails 2.0 too, and is still in 1.2.6.

-Adam

Posted in PostgreSQL, Ruby on Rails | Leave a Comment »

Keep getting kicked off #rubyonrails IRC channel?

Posted by Chirag Patel on October 3, 2007

This is what I did when I was trying to connect to #rubyonrails channel and kept getting thrown into #overflow.

I executed the following command twice (while I was still in #overflow)

/msg nickserv register <your-password>
The first time I ran it, I got the following message:

*** -NickServ- Please wait 120 seconds before using REGISTER again

I waited a while and got this after running it a second time

:*** -NickServ- Your nickname is now registered with the password [<my-password> ].

Last, I ran the following command for good measure:

/msg nickserv register <your-password>

And got the following result:

*** -NickServ- You have already identified

Posted in Ruby on Rails | Leave a Comment »