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

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.


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.

No comments:

Post a Comment