Trying to put in my controller Flash[:notice] = "<%= #{link_to ''edit'', :action => ''edit''} =>" but, I get a "undefined method link_to" error. I would think that the :notice code would be rendered in the view, which should work and not get the "undefined method" error, but this does not seem the case. It appears that its rendered in the controller where I guess this method is undefined. Is there a way to force the rendering to occur in the view? Or am I totally missing something here? --~--~---------~--~----~------------~-------~--~----~ 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 19 Nov 2007, at 04:33, yachtman wrote:> > > Trying to put in my controller > > Flash[:notice] = "<%= #{link_to ''edit'', :action => ''edit''} =>" > > but, I get a "undefined method link_to" error. > > I would think that the :notice code would be rendered in the view, > which should work and not get the "undefined method" error, but this > does not seem the case. It appears that its rendered in the controller > where I guess this method is undefined. Is there a way to force the > rendering to occur in the view? Or am I totally missing something > here? >flash[:notice] is not something magic, it''s just a hash which persists (in the session) across requests, and obviously that srting is just a regular old string, so interpolation happens exactly as it would normally. There''s no rendering going on here. There are various howtos on the web about using view helpers from your controllers, which would be one way of solving your problem. 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 -~----------~----~----~----~------~----~------~--~---
Fred,> flash[:notice] is not something magic, it''s just a hash which persists > (in the session) across requests, and obviously that srting is just a > regular old string, so interpolation happens exactly as it would > normally. There''s no rendering going on here.Understood. But I guess I am confused as to why this would not work, since if I place this exact same code: "ink_to ''edit'', :action => ''edit''}" in the resulting view, it has no problem finding this method and displaying it. So it seems that the utilization of this method "link_to" is happening before it even gets to the view???> There are various howtos on the web about using view helpers from your > controllers, which would be one way of solving your problem.I must admit that I have not utilized these yet, so I''ll do some more homework. Thanks! On Nov 19, 3:47 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 19 Nov 2007, at 04:33, yachtman wrote: > > > > > Trying to put in my controller > > > Flash[:notice] = "<%= #{link_to ''edit'', :action => ''edit''} =>" > > > but, I get a "undefined method link_to" error. > > > I would think that the :notice code would be rendered in the view, > > which should work and not get the "undefined method" error, but this > > does not seem the case. It appears that its rendered in the controller > > where I guess this method is undefined. Is there a way to force the > > rendering to occur in the view? Or am I totally missing something > > here? > > flash[:notice] is not something magic, it''s just a hash which persists > (in the session) across requests, and obviously that srting is just a > regular old string, so interpolation happens exactly as it would > normally. There''s no rendering going on here. > > There are various howtos on the web about using view helpers from your > controllers, which would be one way of solving your problem. > > 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 -~----------~----~----~----~------~----~------~--~---
On 19 Nov 2007, at 07:56, yachtman wrote:> > Fred, > >> flash[:notice] is not something magic, it''s just a hash which >> persists >> (in the session) across requests, and obviously that srting is just a >> regular old string, so interpolation happens exactly as it would >> normally. There''s no rendering going on here. > > Understood. But I guess I am confused as to why this would not work, > since if I place this exact same code: > > "ink_to ''edit'', :action => ''edit''}" > > in the resulting view, it has no problem finding this method and > displaying it. So it seems that the utilization of this method > "link_to" is happening before it even gets to the view???Yes. It''s just an ordinary string you''ve got there so the interpolation happens when it is declared Or to put things another way. if you had a = " #{Time.now} " then Time.now gets evaluated straight away. the fact that you''ve written flash[:notice] instead of a and stuff involving link_to instead of Time.now changes nothing. I''m guessing you thought the use of <%= in your string would make something special happen, but that''s not the case. Fred> > > >> There are various howtos on the web about using view helpers from >> your >> controllers, which would be one way of solving your problem. > > I must admit that I have not utilized these yet, so I''ll do some more > homework. > > Thanks! > > > On Nov 19, 3:47 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> On 19 Nov 2007, at 04:33, yachtman wrote: >> >> >> >>> Trying to put in my controller >> >>> Flash[:notice] = "<%= #{link_to ''edit'', :action => ''edit''} =>" >> >>> but, I get a "undefined method link_to" error. >> >>> I would think that the :notice code would be rendered in the view, >>> which should work and not get the "undefined method" error, but this >>> does not seem the case. It appears that its rendered in the >>> controller >>> where I guess this method is undefined. Is there a way to force the >>> rendering to occur in the view? Or am I totally missing something >>> here? >> >> flash[:notice] is not something magic, it''s just a hash which >> persists >> (in the session) across requests, and obviously that srting is just a >> regular old string, so interpolation happens exactly as it would >> normally. There''s no rendering going on here. >> >> There are various howtos on the web about using view helpers from >> your >> controllers, which would be one way of solving your problem. >> >> 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 -~----------~----~----~----~------~----~------~--~---