Tatva-Artha

meaning of "it"

Archive for the ‘ruby’ tag

Passenger, Apache, Ruby configuration

without comments

Installing passenger to work with apache for rails application is especially pleasant since it gives you direction to setup apache passenger module properly. I have done it several times and it has always worked. Recently I had to change the version of ruby that passenger uses and all I had to do is change the PassengerRuby directive in httpd.conf (or apache.conf) as follows:

#LoadModule passenger_module /opt/ruby-enterprise-1.8.6-20090421/lib/ruby/gems/1.8/gems/passenger-2.2.2/ext/apache2/mod_passenger.so
#PassengerRoot /opt/ruby-enterprise-1.8.6-20090421/lib/ruby/gems/1.8/gems/passenger-2.2.2
#PassengerRuby /opt/ruby-enterprise-1.8.6-20090421/bin/ruby

LoadModule passenger_module /opt/ruby/lib/ruby/gems/1.8/gems/passenger-2.1.2/ext/apache2/mod_passenger.so
PassengerRoot /opt/ruby/lib/ruby/gems/1.8/gems/passenger-2.1.2
PassengerRuby /opt/ruby/bin/ruby

I am not sure if this is the recommended way but it worked for me.

Enjoy!

Written by Sharad

June 2nd, 2009 at 3:45 pm

Posted in All,Technology

Tagged with , ,

Cygwin: installing Webrat on cygwin

without comments

gem install webrat

may fail on cygwin when building native library. In my case, I had to install cygwin package libxslt-devel.

Written by admin

May 26th, 2009 at 7:03 pm

Posted in All,Technology

Tagged with , ,

Ruby 1.8.7: NoMethodError: undefined method `[]‘ for Enumerable::Enumerator

with one comment

After upgrading ruby from 1.8.6 to 1.8.7, you may run into this issue:

NoMethodError: undefined method `[]‘ for Enumerable::Enumerator

To resolve this, create a initializer file (in config/initializer/ruby187_compat.rb)

unless '1.9'.respond_to?(:force_encoding)
String.class_eval do
begin
remove_method :chars
rescue NameError
# OK
end
end
end

Written by admin

May 23rd, 2009 at 12:00 am

Posted in All

Tagged with

Ruby Testing Minimalist support

without comments

I have normally used irb shell or simple ruby scripts to try simple things out. I wondered what would be a minimalist unit test which would lend me all the assertion support and related goodies. Today I have it:

require 'test/unit'
class TestSort < Test::Unit::TestCase
def test_something
assert_equal(x,y)
end
end

Enjoy!

Written by admin

May 22nd, 2009 at 5:19 pm

Posted in All

Tagged with , ,

Ruby Enterprise different from Ruby MRI

without comments

I am in the process of switching a project from Ruby MRI 32-bit to Ruby Enterprise 64-bit. I noticed that they are not exactly the same. For one, the order in which active-record objects are fetched from database is different. This manifests as a failing test assertion when comparing has-many objects. The tests that always passed on ruby MRI fail under Ruby Enterprise.

Also, we noticed that mysql on new machine is different. The primary keys assigned to active-record objects are different from those on old machine. While it is never a good idea to hard-code database IDs for test assertions, it worked never the less since databases are freshly created before each test. This could be due to the architecture differences between those machines (32 vs. 64 bit).

Just a few gotchas …

Written by admin

May 21st, 2009 at 9:23 pm

Posted in All,Technology

Tagged with

CGI escape, unescape, escapeHTML, unescapeHTML

without comments

I just can’t seem to remember which to use when so here are the 4 great helpers when working with URLs and HTML:

When constructing URLs, you use escape and unescape:

url = "http://site.com/?address=" + CGI.escape("123 Main St, City, ST, 99999")
# url: http://example.com/?address=123+Main+St%2C+City%2C+ST%2C+99999

unescape does the reverse.

When rendering text inside HTML page, you use escapeHTML and unescapeHTML:

raw_html = CGI::escapeHTML("<div>An example HTML to be displayed raw on an HTML page</div>") #raw_html: &lt;div&gt;An example HTML to be displayed raw on an HTML page&lt;/div&gt;

unescapeHTML is for converting an html-escaped string back to proper HTML form.

Simple, but you often forget!

Written by admin

May 21st, 2009 at 2:19 pm

Posted in All

Tagged with , ,

ActionMailer, GMail and TLS

with one comment

Prior to rails 2.3.2, if you needed to use GMail as your SMTP carrier (sending out emails from your app), you had to use one of the following plugins to modify the ActionMailer::Base class to support TLS for ActiveRecord.

  • tlsmail
  • ambethia-smtp-tls
  • openrain-action_mailer_tls
  • simplificator-tls-support

In rails 2.3.2, this is supported natively, provided you had proper configuration specified:

config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:enable_starttls_auto => true,
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'localhost.localdomain',
:authentication => :plain,
:user_name => "username",
:password => "password"
}

This should work without any plugins/gems in rails 2.3.2. The only caveat is that ruby version has to be >= 1.8.7. It won’t work with ruby 1.8.6 or older, as documented here.

Enjoy!

Written by admin

May 4th, 2009 at 9:23 pm

Posted in All,Technology

Tagged with ,

Installing passenger/mod_rails on CentOS

without comments

Installing passenger/mod_rails on CentOS sometimes is not as simple as:


$ gem install passenger
and
$ passenger-install-apache2-module

In my case, I also had to install “apr-util-devel” yup package. Also, for some reason the “sudo yum install ” didn’t work for me. I actually had to become root and then perform install.


$ sudo su -
$ yum install apr-util-devel

After this, “gem install passenger” and passenger-apache module install worked fine.

Written by admin

May 4th, 2009 at 9:16 pm

Posted in All,Technology

Tagged with ,

Installing mysql gem on CentOS

without comments

Installing mysql gem on cent-os may sometimes be not as easy as:

$ gem install mysql

It may result in compilation error and fail to install. While this may happen for various reasons, in my case, I had to install “mysql-devel” package.

$ sudo yum install mysql-devel

Once I did this, the mysql gem installed happily.

Written by admin

May 4th, 2009 at 4:26 pm

Posted in All,Technology

Tagged with ,

calling private methods in ruby

without comments

object.method call won’t work if the method is protected or private. Do this instead:

object.send(:method)

Written by admin

April 24th, 2009 at 5:24 pm

Posted in All,Technology

Tagged with