Hi! As I can see it is possible to access local variables inside a block, why can''t I call methods from a block? What I want to do is: render(:update) { |page| page.replace_html ''filterkriterien'', :partial => ''partials/filter'', :locals => { :filter => filter } } filter is a getter method in the calling class. I receive a NoMethodError (undefined method `filter'' for #<#<Class:0xb75c8300>:0xb75c82b0>): Alex. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Rendering in Rails is ''magic'', in that it''s not actually getting run in the context of your controller. The renderer takes your controller''s instance methods ( @varname ) and makes them available to the template. Any methods you try to call will be looked for in the Controller''s Helper module. Seeing as you''re using #render in an action, you''re better off calling and saving the data before the #render call: @filter = filter render(:update) { |page| page.replace_html ''filterkriterien'', :partial => ''partials/filter'', :locals => { :filter => @filter } } Jason On 10/19/06, Alex <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hi! > > As I can see it is possible to access local variables inside a block, > why can''t I call methods from a block? > > What I want to do is: > render(:update) { |page| > page.replace_html ''filterkriterien'', :partial => ''partials/filter'', > :locals => { :filter => filter } > } > > filter is a getter method in the calling class. I receive a > NoMethodError (undefined method `filter'' for > #<#<Class:0xb75c8300>:0xb75c82b0>): > > > > Alex. > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Thanks for your help, my other workaround was for now: caller = self render :update do |page| page.replace_html ''filterkriterien'', :partial => ''partials/filter'', :locals => { :filter => caller.filter } end Alex. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
You can designate controller methods be available to the views by using ''helper_method'' in the controller. Like so: def whatever_controller_method # whatever end helper_method :whatever_controller_method --~--~---------~--~----~------------~-------~--~----~ 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---