Piku’s Blog

January 27, 2008

Testing subdomains as account keys

Filed under: Ruby on Rails — Tags: , , , — Mihai @ 6:49 pm

I am using subdomains as account keys and some tests failed for controllers, they were looking for the account but didn’t find it.

The trick is to rewrite the host in the tests. Here’s the code for rspec.



  before(:each) do

    @request.host = 'piku.mysite.net'

  end

Here, before each test the url is rewritten and the filter that finds the account happily does it job.

January 21, 2008

Rails with_scope tip

Filed under: Programming, Ruby on Rails — Tags: , , , — Mihai @ 10:03 pm

While searching some documentation about has_many :through I’ve found Josh Susser’s blog called (very imaginatively) “has_many :through” and the article about Magic join model creation in Rails Edge.

It is about using << on has_many through associations, before that you could use them only on habtm.

The article is quite old, 19 August 2006, and Rails has changed a bit since then, with_scope is now protected so now instead of

Contribution.with_scope(:create => join_attrs) { self << book }

use

Contribution.send(:with_scope, :create => join_attrs) { self << book }

For more information about many-to-many associations also see Many-to-many Dance-off in which habtm and has_many through is compared and Rails documentation.

January 19, 2008

ActiveRecord ‘type’ error

Filed under: Programming, Ruby on Rails — Tags: , , — Mihai @ 10:03 pm

While playing with Rails and ActiveRecord with has_many :through associations found an interesting error

> Account.find :all
SyntaxError: compile error
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:1748: syntax error, unexpected tINTEGER

It took me some time to figure this out so I thought it might be useful to post it here, maybe someone has the same problem.

The error is because of the ‘type’ attribute of Account model, in Rails it is reserved for single table inheritance. To fix this just do not use an attribute called ‘type’, rename it to something else.

December 26, 2007

NetBeans 6.0

Filed under: Programming, Ruby on Rails — Tags: , , — Mihai @ 10:42 pm

NetBeans 6.0 is now my preferred IDE, it is a great IDE for Ruby and RoR development. It’s very light, having only 19MB (but you also need JDK).

NetBeans Ruby

You can quickly get started, NetBeans comes with JRuby, gems and Rails so you can quickly jump to coding and do not bother with installing Ruby, RoR and dependencies. On the NetBeans website there is a lot of documentation about Ruby support including videos. You can also contribute documentation and plugins.

December 25, 2007

Ruby 1.9 Released

Filed under: News, Programming — Tags: , , — Mihai @ 6:29 pm

The new version of Ruby, 1.9 was recently released (please note that it’s a development version). You can download the packages.

Amongst the hundreds of changes the most important one is the new VM (YARV) that according to some benchmarks drastically increases performance of Ruby. Now I’m waiting for Rails and Mongrel to be compatible.

Happy Holidays Rubyists !

« Newer Posts

Create a free website or blog at WordPress.com.