Probably asked and answered, but... Why are controller private methods inaccessible inside the block passed to render :update ? This does not work: class MyController < ApplicationController def some_action render :update do |page| page.replace_html ''an_element'', some_private_method end end private def some_private_method return ''data'' end end --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
I think this works: class MyController < ApplicationController def some_action some_private_method render :update do |page| page.replace_html ''an_element'', variable_name end end private def some_private_method variable_name = return ''data'' end end On Dec 5, 3:17 pm, kevin cline <kevin.cl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Probably asked and answered, but... > > Why are controller private methods inaccessible inside the block > passed to render :update ? > > This does not work: > > class MyController < ApplicationController > > def some_action > render :update do |page| > page.replace_html ''an_element'', some_private_method > end > end > > private > > def some_private_method > return ''data'' > end > end--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
On 6 Dec 2007, at 16:10, ebrad wrote:> > I think this works: >Guaranteed not to work - you''re just creating a local_variable in a completely different scope. Like i said in a similar thread, a render :update block behaves like a normal view: instance variable are copied over. If you want controller instance methods to be available, they need to be helper methods (see documentation for helper_method) Fred> class MyController < ApplicationController > > def some_action > some_private_method > render :update do |page| > page.replace_html ''an_element'', variable_name > end > end > > private > > def some_private_method > variable_name = return ''data'' > end > end > > On Dec 5, 3:17 pm, kevin cline <kevin.cl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Probably asked and answered, but... >> >> Why are controller private methods inaccessible inside the block >> passed to render :update ? >> >> This does not work: >> >> class MyController < ApplicationController >> >> def some_action >> render :update do |page| >> page.replace_html ''an_element'', some_private_method >> end >> end >> >> private >> >> def some_private_method >> return ''data'' >> end >> end > > >--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Mark Reginald James
2007-Dec-06 17:40 UTC
Re: render :update and controller private methods
Frederick Cheung wrote:> Like i said in a similar thread, a render :update block behaves like a > normal view: instance variable are copied over. If you want controller > instance methods to be available, they need to be helper methods (see > documentation for helper_method)That''s useful to know. An alternative is to call controller instance methods from inside the render block like "controller.meth", or "controller.send(:meth)" for private methods. -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 6, 11:40 am, Mark Reginald James <m...-bzGI/hKkdgQnC9Muvcwxkw@public.gmane.org> wrote:> Frederick Cheung wrote: > > Like i said in a similar thread, a render :update block behaves like a > > normal view: instance variable are copied over. If you want controller > > instance methods to be available, they need to be helper methods (see > > documentation for helper_method) > > That''s useful to know.Yes, but somewhat unexpected. But> An alternative is to call controller instance methods from inside > the render block like "controller.meth", or "controller.send(:meth)" > for private methods.Thanks for that. Ruby is the only language I have that used that supports closures while also allowing methods to be called without an explicit object. I expected that ''self'' would be bound inside the closure at the time the closure was defined. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Possibly Parallel Threads
- using onchange options in forms
- Refresh a partial onClick using ajax call in rails 3.x
- response is null when using should_render_rjs
- Is there a way to abstract the updating of other parts of the page after an Ajax request without putting using the standard view file?
- spec-ing private methods?