can't call method within render block? - trying to extract repetitive page.replace_html

The error:

NoMethodError (undefined method `generate_drawer_data' for #):

caused when the method call is in the block:

respond_to do |format|
  format.js do
    render :update do |page|
      generate_drawer_data(page)

but when the method is outside the block, no runtime errors:

generate_drawer_data()

respond_to do |format|
  format.js do
    render :update do |page|

the method, near the bottom of the controller

 def generate_drawer_data(page = false)
   ... page_replaces
    end

So... why am I getting this behavior?

I'm using ruby on rails 2.3.8

Answers


I believe that block passed to render :update is more like a view, so it has access to controller's instance variable and helpers. Try define this method as helper method using helper_method :generate_drawer_data.


Need Your Help

Copy Table data from one DB to another

python linux osx postgresql

For development I find myself needing to copy table information from one table to another quite often. I am just curious what are the easiest solutions to do this for Postgres. I have PGAdminIII ...

How to avoid default property gotchas in VBA?

vba excel-vba

I only use VBA occasionally, and every time I come back to it I get caught out by some variation of the following:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.