Category: programming

Instant rails application? Come and get it!

Posted by on February 22, 2009

So you want to have a rails application instantly? Thanks to the new application generator functionality of rails 2.3 and my new plugin this is now possible!

How does it work? First, make sure you have installed the rails 2.3 rc1 gem (available at http://www.rubyonrails.org/) and run the following command:

rails example_shop -m http://www.jeevidee.nl/instant_rails_application.txt

This will install a rails application with models, views, controllers, routes, and even translations and fixtures already generated. Plus it will do the migrations and start your server so can you have a look at your new application :).

There is still work to be done, because a good application will not go without tests. The plugin dm_generator is work in progress and I hope I can add this feature soon. Furthermore, the plugin has a low test coverage so bugs are likely to appear. Together with proper documentation this is another TODO item.

If you want to use your own templates, make a fork of dm_templates and change it the way you like it. If you see missing functionality report it here or fork dm_generator and add it yourself. If you have a cool design that you want to show? Please add it to the dm_designs repository by forking it and doing a pull request.

Here is a summary of features that I would like to see myself:

  • Specs/tests for the generator itself
  • Good documentation of the generator
  • Test/Spec and Cucumber templates
  • Better generation of routes
  • Configuration of the default files that should be generated outside of dm_generator manifest

If you see missing features, please suggest them here in the comments.

Slides of my presentation at Amsterdam.rb can be found here or on slideshare

Using I18n to stay DRY in Rails

Posted by on February 14, 2009

One of the new tools in Rails to stay DRY is the new I18n functionality. With this new tool you can keep away from customizing messages, text in your views etc. for your clients/customers, and instead let them to it themselves! Especially with this great new plugin

Some examples:

In your controller:

flash[:notice] = t("controller.#{current_resource}.#{current_action}",
                           :default => "controller.default.action")

If your using something like make_resourceful this becomes even more apparent. I have forked make_resourceful and implemented this which you can check on my github account.

A similar trick can be done in your views:

flash[:notice] = t("view.#{current_resource}.#{current_action}",
                          :default => t("view.default.#{current_action}") )

The only thing you have to is have a yaml file like this:

en:
  controller:
    default:
       create:
         "Succesfully created!
       ....

You can also add the translation of the resource you are working on by adding an option as in the following example:

flash[:notice] = t("view.#{current_resource}.#{current_action}",
                           :default => t("view.default.#{current_action}"),
                           :model => t("activerecord.model.#{model_name}") )

In your yaml file you will just have to add ‘{{model}}’ to include the translation.

en:
  controller:
    default:
       create:
         "Succesfully created {{model}}!
       ....

It might turn out that the above idea with this new feature in rails will make life even easier! Probably more on that in a future post!

Since this is my first blog post here I would welcome some feedback!

Introduction

Posted by on February 14, 2009

Hello readers,

This blog will be a technical blog with (currently) a focus on Ruby and the Rails framework. I will write about my ideas of how things should be done.

That’s it for now. More to come!