From: Brian Candler Date: 2007-03-19T05:40:45+09:00 Subject: Re: accessing methods from the blocks caller On Mon, Mar 19, 2007 at 05:20:05AM +0900, andrew wrote: > I'm experiencing the issue using Rails. I wanted to leave mention of Rails > out of my post as I figured it was simply a Ruby issue, but perhaps not. > > class MyController < ApplicationController > def some_action > render :update do |page| > render_to_string # getting an error that render_to_string > is undefined > end > end > end > > I fix this by doing this... > def some_action > str = render_to_string > render :update to |page| > # use str in the block > end > end This is a rails issue. The *controller* and the *view* are two separate objects; methods defined in the controller are not by default available in the view. The preferred solution is usually to define render_to_string as a helper in app/helpers/mys.rb (as long as it's needed only by the view, not by the controller itself) If you must define it in the controller for some reason, then you can make it available in the view by def render_to_string ... end helper_method :render_to_string > I can ask this in a rails group now if you think it's off topic. It's definitely a rails issue - further questions would best be asked there. Regards, Brian.