Rhodes allows you to create and use helpers, short methods you typically use to DRY your views. Very much the same as the ones you encounter in Rails. There are a number of caveats though.
Helpers are not loaded automatically
In rails you add a module to app/helpers and it gets loaded automatically. Not so in
rhodes. To use a helper you first have to require the file in your controller.
… and include it’s methods into your controller.
class FooController < Rho::RhoController include ApplicationHelper end
… only then you will have access to your helper methods from inside your views.
Using helpers on the homepage.
The default homepage is at app/index.erb This view is not managed by a controller therefore you can’t just include your helper methods. Here is a workaround.
First create a separate Rhodes model; it will serve as an alternative homepage.
rhogen model Home name
Note the name property we’re adding. We don’t need it but rhogen requires atleast one property on a model so we’re adding a dummy. C’est la vie.
A bunch of files will be created in app/Home/. You can remove all .erb’s except for the index.erb which will replace the original view at app/index.erb. Similarly you can remove all actions in the controller, except for the index action.
Finally, open up rhoconfig.txt and change the start_path value to ‘app/Home/index’. You can now include your helper functions and use them on the homepage.