Steffen Hi, the name's Steffen and I'm writing about the Web, programming and all those things coming to my mind. Enjoy your stay.

I'm currently working on fabidoo.com - 3D Printing for everyone!

Archive for the ‘Ruby on Rails’ Category

RDT and RadRails Keyboard Shortcuts

Thursday, February 8th, 2007

RDT together with RadRails on Eclipse is a pretty convenient development environment when doing things in Ruby on Rails. A little unknown are the keyboard shortcuts, which make your day even more productive. Here’s a list of those:

Ctrl-Alt-T

Jump to the test case of a model or controller and vice versa.

Ctrl-Shift-V

Jump to the view of a controller method and vice versa.

Ctrl-Alt-X

Factor out a partial from a view. Simply select the code block you want to factor out into a separate partial an press the key combination. A window opens an you can enter the name for the new partial (dont’t forget the _ and the .rhtml).

Ctrl-Shift-F

Auto-format the selected code (Ruby only). Not that mature, yet, and seems to have problems with regular expression - currently not recommended to use.

Ctrl-Shift-C

Toggle comment (Ruby only), i.e. the selected code block will be commented out if it wasn’t (# are inserted in the first column of each row), and vice versa.

 

Especially jumping between models/controllers and their test-cases/views saves you a lot of hassle like “where’s that file again in my damn folder hierarchy”, especially when your project gets larger.

Oh and one more thing: The listed shortcuts are the ones coming with RDT/RadRails additionally to the ones already included in Eclipse. You can always check those out via Window->Preferences->General->Keys. Gems are awaiting you ;-)

Tags: , , , , , ,

Redirecting $stdout to Logger with Ruby on Rails

Thursday, November 16th, 2006

Ruby on Rails on FastCGI on Apache is a pretty fast and robust combination. Unfortunately FastCGI do doesn’t like output on “standard out”, i.e. $stdout in Ruby. Brian Pontarelli has an article concerning the problem. His suggestion is to simply have no puts in your code. The standard lib of Ruby however sometimes prints exceptions to the console - REXML is one popular example.

Brian also mentions the idea to redirect anything printed to $stdout to a logger. That means however, that all output given by web servers like Webrick would also end up in some log file - which isn’t the best thing for your development and debugging sessions.

Eric Hodel on the other hand found a pretty nice way to redirect $stdout for only some Ruby threads.

Using those two techniques I came up with a solution that turns on $stdout redirection with the beginning of an HTTP request and turns it off once the Rails controller finished its work. Problem solved ;-) - everything printed to $stdout in your controllers will end up in your development/production/test.log. (more…)

Ruby on Rails flashes with JavaScript accessors

Tuesday, August 22nd, 2006

Ruby on Rails has loads of cool features. One of those is the support for flashes.
As long as your HTML template follows some rules, you can use flashes to inform your user about things that happened within the last server interaction.

These rules are pretty simple, but adding the necessary things to your HTML templates is always the same thing. Since Rails teaches us not to reinvent the wheel ;-) I’ve written a neat little helper for that issue. It also comes with some JavaScript methods so you can clear flashes or show new ones within your JavaScript application flow. (more…)

You are currently browsing the archives for the Ruby on Rails category.

53525