« Synergy: One keyboard (and mouse) to rule them all | Main | Rails 1.1.5 Brouhaha »

August 05, 2006

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00e398212d6f883300e3982162c98833

Listed below are links to weblogs that reference Rails: Calling render() outside your Controllers:

Comments

Matias

Great, but... How to pass variables to the template?? I've tried with :locals=>{:somevar=>'value'} and doesn't works.


Thanks

choonkeat

Yea, I haven't figured that out yet. maybe when I need it - my problem that day was to render a rxml file with variables from elsewhere.

Sure would love to hear any solution. Can probably tweak DummyController, but I'm not very sure.

willc

You can actually render a template with a one liner, .eg:


ActionView::Base.new(Rails::Configuration.new.view_path).render(:partial => 'foo/bar', :locals => {:foo => 'bar'})

choonkeat

@willc: much better! thanks :-)

Dave Troy

This has come up often for me and I wanted a more elegant solution. So I put together ActsAsRenderer to give models a simple and elegant way to render output to strings or files.

Please see:
http://davetroy.blogspot.com/2008/02/actsasrenderer-brings-output-to-models.html

Adam

Setting instance variables for the templates is easy: just add the name and value to the ActionView instance's @assigns hash, like this:

av = ActionView::Base.new(Rails::Configuration.new.view_path)
av.assigns[:foo] = "bar"
av.render "some/template/here"

Jeff

Thanks for sharing this. I've got it mostly working but need to use UrlHelpers.

In other words, I'd like to include things like this in my templates (bad example):

Suggestions on how to do this?

Thanks
Jeff

Jeff

Er, looks like it stripped out the rhtml which is the following wrapped correctly:
link_to 'Edit', edit_user_path(@user)

Olivier

You could use:

result = ERB.new(template_content).result(binding)

Olivier

eric

Adam's suggestion worked for me. The RenderAnywhere did not! Rails 2.3.3.

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

My Other Stuff

Blog powered by TypePad