Thursday, August 31, 2006

Using Comatose With rForum

Several people have been reporting issues with rForum. The error messages can be a little deceiving, leading you to believe the error is in navbar.rb or a @Localization@ class.

Actually, the problem has to do with Rails’ loading sequence. Plugin code is loaded before the application code. In some applications this can lead to problems.

So, you have two options for fixing the rForum problem.

Option One

Remembering that plugins are loaded alphabetically, we create a simple plugin that will load before Comatose that includes the appropriate rForum startup code.

In the console, enter:

./script/generate plugin 01_app_loader

It should spit out:

  create  vendor/plugins/01_app_loader/lib
  create  vendor/plugins/01_app_loader/tasks
  create  vendor/plugins/01_app_loader/test
  create  vendor/plugins/01_app_loader/README
  create  vendor/plugins/01_app_loader/Rakefile
  create  vendor/plugins/01_app_loader/init.rb
  create  vendor/plugins/01_app_loader/install.rb
  create  vendor/plugins/01_app_loader/lib/01_app_loader.rb
  create  vendor/plugins/01_app_loader/tasks/01_app_loader_tasks.rake
  create  vendor/plugins/01_app_loader/test/01_app_loader_test.rb

Then you open the vendor/plugins/01_app_loader/init.rb file and paste this into it:

require RAILS_ROOT + '/config/app'

That’s it! It should work now, as you’d expect.

Option Two

Update the vendor/plugins/comatose/init.rb and add the same require RAILS_ROOT + '/config/app' to the very top of the file.

I don’t really recommend this way, however. You’d have to redo it if you updated Comatose.

Notes

If you’ve already installed Comatose, you’ll need to uninstall it before you create the new plugin. After you’ve pasted the startup code, you can re-install Comatose, generate the migration and go to town!

Oh, And I'm Back

I forgot to mention, I made back from my vacation and seemingly requisite post-vacation sickness. For all you guys who kept an eye on the forums whilst I was away: Thanks! I really appreciate it.

I mentioned somewhere that there might be an asset manager in the next version of Comatose. While I did look into it, and had it mostly working, I’ve reconsidered. I think that an asset manager might make a good plugin of it’s own, but it’s probably too much for Comatose. It wouldn’t feel quite so ‘Micro’.

Revisions, however, are definitely on the list for version 0.7!

Wednesday, August 2, 2006

Inline Rendering with ActionMailer

Notes from David Vrensk on how to use Comatose’s inline rendering with ActionMailer:

My app has to send out confirmation emails, and I use ActionMailer to do that. I want the site owner to be able to update (part of) the email template, so I put that part in a Comatose page. In the email template, I put

<%% render :comatose => "email-text" %>

But this triggers the error

ActionView::TemplateError (undefined method `read_fragment' for #<Notifier:0x23849e4>) on line #15 of
app/views/notifier/order_confirmation.rhtml:
...
    #{RAILS_ROOT}/vendor/plugins/comatose/lib/support/inline_rendering.rb:30:in `render_cached_comatose_page'
    #{RAILS_ROOT}/vendor/plugins/comatose/lib/support/inline_rendering.rb:20:in `render_comatose'
    #{RAILS_ROOT}/vendor/plugins/comatose/lib/support/inline_rendering.rb:7:in `render'
    #{RAILS_ROOT}/app/views/notifier/order_confirmation.rhtml:15:in `_run_rhtml_order_confirmation'

(Notifier is my descendant from ActionMailer::Base.) Apparently, ActionMailer tells ActionView that it is the calling controller. That’s duck typing for you.

I don’t have a fix (don’t know Rails or Comatose well enough yet), but I have a work-around if anyone is interested:

  1. Comatose only tries to call #read_fragment if it uses fragment caching. So, turn of fragment caching for this call:

    <%% render :comatose => "email-text", :use_cache => false %>
    
  2. Comatose will now try to render as usual, passing the original request parameters to the Page. But to do this, it has to pick up the params from the controller. Again, the controller is unavailable, but this page doesn’t need the params anyway, so I fake them by adding

    def params Hash.new end

to Notifier, my ActionMailer::Base descendant. And now, all is good. Hacky, but good.

Thanks David!

Tuesday, August 1, 2006

Version 0.6.9

Checked in a small update… Added support for getting certain sibling/child pages: page.next, page.previous, page.first_child, and page.last_child.