Abbas K. Sutarwala
2008-May-18 12:51 UTC
Problem with rjs accessing a controller instance variable.
> Hello. > > My rjs cannot obtain the instance variable set up in the associated > controller method. I have described the code below. Will > appreciate any thoughts on "why". I am using InstantRails on Windows XP > with the Rails version of 2.0.2. > > I have the following code (simplified) > > in LearnController.rb > > def page_via_ajax > # debugger > render :layout => false > puts("in LearnController.page_via_ajax method") > @my_page_id = "pg_7" > end > > > in page_via_ajax.rjs > > puts("in page_via_ajax.rjs") > puts("@my_page_id:#{@my_page_id}:") > > > System output: > > in LearnController.page_via_ajax method > in page_via_ajax.rjs > @my_page_id:: > > > Apparently the rjs file does not get the value of the @my_page_id instance > variable created in the controller. > > What are the reasons and what is the solution? > > > With thanks and regards, > > Abbas >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-May-18 15:18 UTC
Re: Problem with rjs accessing a controller instance variable.
On 18 May 2008, at 13:51, Abbas K. Sutarwala wrote:> >> Hello. >> >> My rjs cannot obtain the instance variable set up in the associated >> controller method. I have described the code below. Will >> appreciate any thoughts on "why". I am using InstantRails on >> Windows XP >> with the Rails version of 2.0.2. >> >> I have the following code (simplified) >> >> in LearnController.rb >> >> def page_via_ajax >> # debugger >> render :layout => false >> puts("in LearnController.page_via_ajax method") >> @my_page_id = "pg_7" >> end >> >>>> >> Apparently the rjs file does not get the value of the @my_page_id >> instance >> variable created in the controller. >> >> What are the reasons and what is the solution? >>The render happens when you call render (is this surprising?), and you assign to @my_page_id after you call render. Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
AbbasKS
2008-May-19 04:59 UTC
Re: Problem with rjs accessing a controller instance variable.
Thanks, Fred! I assumed that "render :layout => false" was a configuration setting which would be used whenever Rails renders and did not realise that the statement would actually render! With regards, Abbas On May 18, 8:18 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 18 May 2008, at 13:51, Abbas K. Sutarwala wrote: > > > > > > >> Hello. > > >> My rjs cannot obtain the instance variable set up in the associated > >> controller method. I have described the code below. Will > >> appreciate any thoughts on "why". I am using InstantRails on > >> Windows XP > >> with the Rails version of 2.0.2. > > >> I have the following code (simplified) > > >> in LearnController.rb > > >> def page_via_ajax > >> # debugger > >> render :layout => false > >> puts("in LearnController.page_via_ajax method") > >> @my_page_id = "pg_7" > >> end > > >> Apparently the rjs file does not get the value of the @my_page_id > >> instance > >> variable created in the controller. > > >> What are the reasons and what is the solution? > > The render happens when you call render (is this surprising?), and you > assign to @my_page_id after you call render. > > Fred--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---