Current Active Scaffold Rails plugin (1.1.1) not compatible with Rails 2.1

If you’re seeing errors like this

... gems/activesupport-2.1.0/lib/active_support/core_ext/module/aliasing.rb:31:in `alias_method': undefined method `find_full_template_path' for class `ActionView::Base' (NameError)

You’re not crazy.
Active Scaffold (1.1.1) doesn’t play nice with Rails 2.1!

Go here to get an Active Scaffold version (master) that does.

The haters crawl out of the woodwork on mod_rails project

There has never been a statue erected to honor a critic.
– Ziglar, Zig

I couldn’t believe that someone would have the gall to actually go on record with grouses as trite as these against the creators of mod_rails … but they did

Basically here are their complaints about Phusion Passenger/mod_rails

– Their product has ‘Enterprise’ in the title
– They shouldn’t be up to version 2.0 already (yes … they actually said that)
– They release FREE products ‘late’ (late being an excruciating 2 weeks)
– They’d like for them them to be more ‘modest’ (like they haven’t heard of DHH)
– The marketing seems too slick and something ‘fishy’ is going on because they’re trying to make money with an Enterprise ready version of Passenger/mod_rails?!?!
– The ‘rails community’ will not embrace mod_rails because of these laughable quibbles … I guess these guys don’t count as part of the ‘rails community’ right?

ridiculous.

PS: Note that the original ‘rant’ appeared on Ruby flow, where it was rightly eviscerated

mod rails Passenger 2.0 RC2 released … even more stable?

The kickass developers over at Phusion have released an update to Phusion passenger (or as I prefer to call it … Apache mod rails).

You can see the list of original improvements here

It seems that this particular problem with mod-rails hanging after a few hours and taking down apache with it (I experienced this in an apache deployment that I tried personally … and its a bit scary) was part of the motivation behind the original mod_rails/Passenger Release Candidate. Continue reading

(98)Address already in use: make_sock: could not bind to address 0.0.0.0:443

I ran into this problem after I installed mod-rails on a cent OS server.

To get my changes to take … I kept running

httpd -k graceful

and it kept working until, all of a sudden, it didn’t.

This was the error I got

[XXXX@XXXXXXXXX]# httpd -k graceful
httpd not running, trying to start
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:443
no listening sockets available, shutting down
unable to open logs

argh!

Then I found this marvellous blog posting on how to fix the “Address already in use: make_sock: could not bind to address – Apache – HTTPD Error”

Here is what I did. (click to enlarge)

worked like a charm too.

Ruby on Rails gotcha: undefined method `rewrite’ for ….

undefined method `rewrite' for "":String

If you get this error, and the error message is pointing you to a “link_to” call or something similar, then you may be using an instance variable that’s called ‘@url’ too.

This blog post did talk about the problem but it seemed limited to models only. I finally discovered that, in my case, I was using ‘@url’ in the controller for the view where I was making the ‘link_to’ call.

Long story short, if you see this error, comb through your code (models, controllers and views) for any variables that are called ‘@url’  and change them.

Dreamhost now supports mod_rails on their shared hosting plans

Dreamhost now supports the use of mod_rails on their shared hosting plans

The Phusion team contacted me with a working test version of Passenger a couple of months ago and since then DreamHost has been helping out with testing and ironing out lingering deployment issues.  The Phusion team has been very helpful and responsive throughout the process and I think we will see a lot more great things from them in the future.

Now to the important part… how do you use Passenger on DreamHost?

Briefly, all you do is enable the Ruby on Rails Passenger (mod_rails) option for any existing or new web domain in the DreamHost web control panel. When you then point that domain’s web directory to the public directory of an existing Ruby on Rails application it will work automatically.  For more detailed information, check out our Passenger wiki page.

php’s print_r equivalent in ruby on rails

I was going through my google analytics logs today and I noticed that a lot of folks were coming to my site on Google searches for stuff like ‘print_r + ruby on rails‘.

So I figured I’d write a blog post about it, because I’ve had the same problem.

What you’re looking for is ‘inspect’.

If you have an array, hash or object that you want to take a quick-and-dirty look at just type in

objectname.inspect

eg:

posts.inspect

or if you’re in rails just do …

render :text => posts.inspect and return false

and you’ll get an output of the contents of said array, hash or object.

Here is a screen capture of a quick irb session to show you how it works.

print_r equivalent in ruby on rails

I hope this helps.

Gotcha in Ruby for PHP Developers with multiple assignments of array to variables

The more I work with Ruby and Ruby on Rails, the more I begin to understand (though not necessarily agree with) a lot of the vitriol that has been aimed at PHP over the years by developers using other more rigorous languages.

A few weeks back I ran into this little speed bump while working with Ruby on Rails, where I was  trying to do a multiple assignment like this

x = y = z = []

Most seasoned Rubyists will be waving their arms around and yelling “NOOOOOO!!!”
But coming from a PHP background this seemed perfectly okay to me.

Continue reading

Ruby on Rails: How to get the output from an action (render_component_as_string)

This one took a little bit but I finally figured it out …

@xml = render_component_as_string :controller => “quote”, :action => “xml”, :params => {:request_id => 100}

This would run the action “xml” of the controller “quote” and pass the parameter  “100” to it to do so.

Whatever would have been displayed at /quote/xml/100 is now stored in @xml

This allows you get the output from any action …. anywhere, also allowing you to pass parameters to it in the process.

Even better, this actually runs the action and its view (unlike render :action, which just renders the action view).

For more details, go to the Ruby On Rails Manual > Using components

Apache Mod Rails released!!!

After weeks of anticipation , the apache module that allows you to upload your ruby on rails application to the server and have it “just work” has just been released.

I’ve just downloaded the source code from their git repository (git rocks!!) and am trying to see if it’ll install on windows.

Update: It won’t install on windows and there are no plans to ever allow it to (damned Linux elitists!!! :P).

mod_rails released!

fixing webrick error – WARN TCPServer Error: Bad file descriptor – bind(2) – on windows

I was working on a Ruby on Rails project with Netbeans today when I went to fire up webbrick to test something in the app.

I immediately got an error like this

=> Booting WEBrick...
=> Rails application started on http://0.0.0.0:3000
[2008-03-18 16:36:59] INFO  WEBrick 1.3.1
=> Ctrl-C to shutdown server; call with --help for options
[2008-03-18 16:36:59] INFO  ruby 1.8.6 (2007-03-13) [i386-mswin32]
[2008-03-18 16:36:59] WARN  TCPServer Error: Bad file descriptor - bind(2)
C:/ruby/lib/ruby/1.8/webrick/utils.rb:73:in `initialize': Bad file descriptor - bind(2) (Errno::EBADF)
        from C:/ruby/lib/ruby/1.8/webrick/utils.rb:73:in `new'
        from C:/ruby/lib/ruby/1.8/webrick/utils.rb:73:in `create_listeners'
        from C:/ruby/lib/ruby/1.8/webrick/utils.rb:70:in `each'
        from C:/ruby/lib/ruby/1.8/webrick/utils.rb:70:in `create_listeners'
        from C:/ruby/lib/ruby/1.8/webrick/server.rb:75:in `listen'
        from C:/ruby/lib/ruby/1.8/webrick/server.rb:63:in `initialize'
        from C:/ruby/lib/ruby/1.8/webrick/httpserver.rb:24:in `initialize'
        from C:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick_server.rb:58:in `new'
         ... 7 levels...
        from C:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39
        from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
        from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
        from script/server:3

Continue reading

Apparently the creator of Ruby on Rails doesn’t comment his code … kinda

Here’s some excerpts from DHH’s post and comments yesterday on 37 signals

  • The short answer is that we don’t document our projects. At least not in the traditional sense of writing a tome that exists outside of the code base that somebody new to a project would go read …
  • Further more, I don’t really find it necessary for the kind of work that we do. Our biggest product, Basecamp, is about 10,000 lines of code. That really isn’t a whole lot in the grand scheme of things. Everything we do is build is also using Ruby on Rails, which means that most Rails programmers would know their way around our applications straight away. It’s the same conventions and patterns used throughout.
  •  Finally, we write our application in a wonderfully expressive and succinct programming language like Ruby that leads itself very well to a programming style like the one Kent Beck preaches in Smalltalk Best Practice Patterns. Keep your methods short and expressive. On average, our models have methods just four lines long. Adding documentation to a method should usually only be done when you’re doing something non-obvious that can’t be rewritten in an obvious way.
  • [comment] Wim, yes there’s RDoc. I just generally don’t use it for projects. When methods are only an average of 4 lines long written in a language like Ruby, it’s often faster and better to merely browse the code base rather than rely on explicit commenting.

Keep in mind that I’m no Ruby on Rails genius, and from the little I’ve done I can see where DHH is going with this. But I’ve always thought that this argument of a language being so succinct and clear that you don’t have to write comments is just a bit silly for a couple of reasons.

  • I believe that you don’t write code for machines, you write code for people (other developers). So any help you can give them in navigating your code is typically good to have. It saves them time and their employers money … that is what being a great consultant is about, you have to be thinking in terms of how to help your clients’ business and saving them money falls in that category.
  • People who use this line of argument are either too lazy to comment and are trying to justify it …
  • … or don’t understand that there are developers of all skill levels in the industry. So whereas, someone with your skill level would be able to navigate your code quickly, someone who wasn’t as good might take longer …why not avoid that.

Note, that I’m not of the school of thought of commenting just for the sake of it, like I’ve heard some “blub programmers” do. However, I do think that you should always be thinking of other developers when you code and if commenting can get them to a point where they can modify your code in 1 minute instead of a minute and a half … then you should comment.

In the end, I guess its a bit unfair to criticize DHH, because its not clear that he doesn’t comment his code much … though its easy to infer that. I just know from my experience that people who say things like he says have a tendency to have 3 lines of comments in some piece of code 500 lines long.

But if you’re a “rockstar developer, I guess everyone has to dance to your tune, wherever you are right?

Ruby reddit and top ten list of Ruby gems!

Quick note to say that  I just discovered the brand new Ruby Reddit which is really fortuitous now that I’m spending a lot of time with Ruby on Rails. From there I found the “Ten Essential Ruby Gems” … which I am installing and screwing with as I type :]

Many thanks  to Reginald Braithwaite who runs the immensely popular software development blog Raganwald for his post about the Ruby Reddit.

random dude on the “internets” disembowels Ruby on Rails …

I spent the whole weekend reading about Rails setup and deployment, discovering Ngnix + mongrels as a new Rails hosting setup option and started getting in depth with Rails with Obie Hernandez’s “The Rails Way“.

I don’t know much about the guts of PHP or Rails (that is something I am working very hard to remedy) but I was fascinated by this google group post  “Rails is shitty” … Continue reading