We're putting together a searchable online help site in Rails, and I'm
using FastRI to full-text index some existing Rails view pages to do
it.

I don't want to use Sphinx or some other solution, just because it's
way overkill for the 15-20 .html.erb partials I am looking to index.

So... I need to violate MVC (flog me now)... trying to write a Ruby
class that renders each of these pages as a string, and feeds the
rendered text as a string into FastRI for indexing.

I've seen plenty of links, most of which have about the same
approach.

Here are a few of the approaches I have seen:

http://railsforum.com/viewtopic.php?id=16885
http://www.compulsivoco.com/2008/10/rendering-rails-partials-in-a-model-or-background-task/
http://ethilien.net/archives/render-rails-templates-anywhere-even-in-a-model/
http://www.swombat.com/rails-rendering-templates-outside-of-a-contro

All seem to work until I try to render a page with a link_to helper
with a restful route (games_path) or a hash representing the path.

As best I can tell, I think I need a controller and some kind of mock
request.

Using a slight derivation from the more recent blog post:

def render_anywhere(partial, assigns={})
  view = ActionView::Base.new(Rails::Configuration.new.view_path,
assigns)
  ActionView::Base.included_modules.each { |helper| view.extend
helper }
  view.extend ApplicationHelper
  view.render(partial)
end

render_anywhere(:file => "/full/path/to/app/views/helps/
_send_credentials.html.erb")

gives me this:

ActionView::TemplateError (You have a nil object when you didn't
expect it!
The error occurred while evaluating nil.url_for) on line #6 of app/
views/helps/_send_credentials.html.erb:

actionpack (2.3.4) lib/action_view/helpers/url_helper.rb:85:in `send'
actionpack (2.3.4) lib/action_view/helpers/url_helper.rb:85:in
`url_for'
app/views/helps/_send_credentials.html.erb:6


As best I can tell, I'm missing a controller and possibly a request
object in there somewhere, since it seems to be barfing on:

@controller.send(:url_for, options)

I've tried assigning a mock controller in there, and then it looks
like the controller needs a request object. I've tried following the
rabbit down the hole, and I just keep getting "nil object when you
didn't expect it" errors of various flavors.

I'm lost, any ideas?

Thanks in advance--

Jeff Wigal
-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.


Reply via email to