Chronicling my experiences with ruby on rails, web application development/management.

Showing posts with label generator. Show all posts
Showing posts with label generator. Show all posts

Tuesday, December 16, 2008

Rails Engines are awesome!!!!

Some of my loyal fans may be shocked to know that i just tried the Rails Engines plugin. Officially titled engines plugin on github.


So easy, and exactly as advertised


Sometimes, try as we may, things aren't always as advertised in this community of ours. So it is a good when things go exactly as planned


Instructions on using the plugin are well written in the README, so i won't bore you with those details, but if you have ever wanted to make a plugin that had the same familiar structure as your rails app', then this is for you. All you need to do is create a plugin and then add the same app directory structure in the root folder of the plugin.


Predictions


Theoretically you can make all of your controller, models and views as plugins, making your app act almost like it's own SAAS appliance. If you have a generator style'd plugin, there is no reason not to use engines. Less coding for you, the plugin creator.


Examples of Hot Rails Engines Action (HREA?)


In fact, i just put the finishing touches on my fork of the rails stat plugin, that was purely a generator script, basically. Now in my forked version, the engines plugin takes care of generating static code within an app. And that is pretty frickin cool.

Saturday, December 13, 2008

Working with Generators in Rails - Lessons Learned the hard way.

I'm updating a plugin that works in Rails 2.2.2 development, yet borks in a production site using 2.1.0.

undefined method `render' for # Rails::Generator::Commands::Create:0x7fdf1caaa2c8


right now, Here is what the problem was


in my generator script i had the usual code
m.template "app/views/rail_stat/hits.rhtml", "app/views/rail_stat/hits.rhtml"
m.template "app/views/rail_stat/lang.rhtml", "app/views/rail_stat/lang.rhtml"

Now inside of hits.rhtml is the following line
< %= render :partial => 'menu' % >

For some reason the render part fudges everything up. if i delete that line, the files go through with no problem.


Solution


When generating erb templates, the Rails::Generator needs to use an extra percentage sign whenever you call specific erb calls. For instance, i only had used < %= render :partial => 'menu' % > but i should have used < %%= render :partial => 'menu' % >
Again, notice the extra % percentage sign in the second code bit. I'm sure there may be a better reason but the second % sign acts almost as a buffer and tells m.template to print the erb code in the new file? Again, that may be too simplistic of an answer, but that is what it seems like to me.