Hi again, sorry for many questions. In mi HomeController, I have the "hi" method, in this method I use an "if" for show a different message for a registered user or a guest. When I call in "home/index" my method "hi", show me this error message: "Stack level too deep" class HomeController < ApplicationController def hi if (current_user) @username = current_user_session.user.username @welr = ''¡Bienvenid@ '' + @username.to_s + '' a nuestra web!'' render ''home/index'' else @weli = "¡Bienvenid@ invitad@, no dude en registrarse!" end end end # home/index <p>Holaaaa</p> <%= @controller.hi %> Well, I have trying find the solution, but I haven''t can. Can anyone help me? Rewards, Iván -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
most likely @username = current_user_session.user.username which will probably work better as @username = current_user.username and @welr = ''¡Bienvenid@ '' + @username.to_s + '' a nuestra web!'' is better as @welr = "¡Bienvenid@ #{@username} a nuestra web!" On Sat, Jun 11, 2011 at 10:06 AM, Distriker <ivanhcelrinconelmejor-Re5JQEeQqe8@public.gmane.orgm> wrote:> Hi again, sorry for many questions. In mi HomeController, I have the > "hi" method, in this method I use an "if" for show a different message > for a registered user or a guest. When I call in "home/index" my > method "hi", show me this error message: > > "Stack level too deep" > >> class HomeController < ApplicationController > def hi > if (current_user) > @username = current_user_session.user.username > @welr = ''¡Bienvenid@ '' + @username.to_s + '' a nuestra web!'' > render ''home/index'' > else > @weli = "¡Bienvenid@ invitad@, no dude en registrarse!" > end > end > end > > # home/index > <p>Holaaaa</p> > <%= @controller.hi %> > > Well, I have trying find the solution, but I haven''t can. Can anyone > help me? > > Rewards, Iván > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 11 Jun 2011, at 19:06, Distriker wrote:> Hi again, sorry for many questions. In mi HomeController, I have the > "hi" method, in this method I use an "if" for show a different message > for a registered user or a guest. When I call in "home/index" my > method "hi", show me this error message: > > "Stack level too deep" > > class HomeController < ApplicationController > def hi > ... > render ''home/index'' > ... > end > end > > # home/index > <p>Holaaaa</p> > <%= @controller.hi %>You are rendering home/index which is calling hi which is rendering home/index which is calling hi which is rendering home/index which is calling hi which is rendering home/index which is calling hi which is rendering home/index which is calling hi which is rendering home/index which is calling hi which is… The whole thing is wrong anyway. The "hi" method should be a helper and not a controller method, it shouldn''t render anything either. Using @controller should be avoided for the kind of thing you want to do (if used at all to start off with, unless you want to show some logging in your views in development mode) All you want is class HomeController < ApplicationController def index end end class HomeHelper < ApplicationHelper def hi .... end end # home/index <p>Holaaaa</p> <%= hi %> Best regards Peter De Berdt -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sat, Jun 11, 2011 at 1:06 PM, Distriker <ivanhcelrinconelmejor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> Hi again, sorry for many questions. In mi HomeController, I have the > "hi" method, in this method I use an "if" for show a different message > for a registered user or a guest. When I call in "home/index" my > method "hi", show me this error message: > > "Stack level too deep" > > class HomeController < ApplicationController > def hi > if (current_user) > @username = current_user_session.user.username > @welr = ''¡Bienvenid@ '' + @username.to_s + '' a nuestra web!'' > render ''home/index'' > else > @weli = "¡Bienvenid@ invitad@, no dude en registrarse!" > end > end > end > > # home/index > <p>Holaaaa</p> > <%= @controller.hi %> > >Lo que estas tratando de hacer aqui se hace en los helpers no en el control , las funciones que se desea usar para generar texto o algun valor en la vista se colocan en los helper, los controles se usan para procesar request y no tiene sentido hacer que desde el index se llame a hi pues generas un request para index y cuando este se genera llamas a hi con otro request que de hecho necesita una ruta y un render para funcionar como quieres, pero la solucion mas simple es poner esta funcion en un helper. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sat, Jun 11, 2011 at 1:06 PM, Distriker <ivanhcelrinconelmejor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> Hi again, sorry for many questions. In mi HomeController, I have the > "hi" method, in this method I use an "if" for show a different message > for a registered user or a guest. When I call in "home/index" my > method "hi", show me this error message: > > "Stack level too deep" > > class HomeController < ApplicationController > def hi > if (current_user) > @username = current_user_session.user.username > @welr = ''¡Bienvenid@ '' + @username.to_s + '' a nuestra web!'' > render ''home/index'' > else > @weli = "¡Bienvenid@ invitad@, no dude en registrarse!" > end > end > end > > # home/index > <p>Holaaaa</p> > <%= @controller.hi %> > > Well, I have trying find the solution, but I haven''t can. Can anyone > help me? > > Rewards, Iván > >tambien puedes hacerlo de esta forma def index @welcome = hi end private def hi if user_signed_in? return "¡Bienvenid@ #{current_user.username} a nuestra web!" else return "¡Bienvenid@ invitad@, no dude en registrarse!" end end y en la vista <p>Holaaaa</p> <%= @welcome %> nunca interpoles (sustituyas variables en cadenas) usando + (signo de mas), en ruby siempre es preferible user #{ }. Esta forma que he puesto es por si insisten en usar la funcion desde el control, como dije antes, las funciones en los controles que se acceden desde la vista siempre son para procesar request, no los generes sin pensar la secuencia que se crea en el server. Si desea funciones en a vista usa los helpers, declaralas ahi y luego llamalas desde la vista , estaran accecible sin problema. En los controlles pueden poner funcione para procesar sierta logica y no request, y lo que se hace es que solo se hace para acceder de desde el control mismo y se protegen con un private. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 06/11/2011 07:40 PM, radhames brito wrote:> > > On Sat, Jun 11, 2011 at 1:06 PM, Distriker > <ivanhcelrinconelmejor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > <mailto:ivanhcelrinconelmejor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> wrote: > > Hi again, sorry for many questions. In mi HomeController, I have the > "hi" method, in this method I use an "if" for show a different message > for a registered user or a guest. When I call in "home/index" my > method "hi", show me this error message: > > "Stack level too deep" > > class HomeController < ApplicationController > def hi > if (current_user) > @username = current_user_session.user.username > @welr = ''¡Bienvenid@ '' + @username.to_s + '' a nuestra web!'' > render ''home/index'' > else > @weli = "¡Bienvenid@ invitad@, no dude en registrarse!" > end > end > end > > # home/index > <p>Holaaaa</p> > <%= @controller.hi %> > > Well, I have trying find the solution, but I haven''t can. Can anyone > help me? > > Rewards, Iván > > > tambien puedes hacerlo de esta forma > > def index > @welcome = hi > end > > private > def hi > if user_signed_in? > return "¡Bienvenid@ #{current_user.username} a nuestra web!" > else > return "¡Bienvenid@ invitad@, no dude en registrarse!" > end > end > > y en la vista > > > <p>Holaaaa</p> > <%= @welcome %> > > > nunca interpoles (sustituyas variables en cadenas) usando + (signo de > mas), en ruby siempre es preferible user #{ }. > Esta forma que he puesto es por si insisten en usar la funcion desde > el control, como dije antes, las funciones en los controles que se > acceden desde la vista siempre son para procesar request, no los > generes sin pensar la secuencia que se crea en el server. Si desea > funciones en a vista usa los helpers, declaralas ahi y luego llamalas > desde la vista , estaran accecible sin problema. En los controlles > pueden poner funcione para procesar sierta logica y no request, y lo > que se hace es que solo se hace para acceder de desde el control mismo > y se protegen con un private. > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en.Hi Martin, Peter and Radhames, I understand your explanations, I put my function "hi" in HomeHelper and I call the method with <%= hi %> from my "home#index", but give me an error: superclass must be a Class (Module given) I have searched in Google a solution or the explanation, but I don''t find. I am still thinking it might be happening... Regards, Iván -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
please confirm that the code in the helper is like this module HomeHelper def hi if user_signed_in? return "¡Bienvenid@ #{current_user.username} a nuestra web!" else return "¡Bienvenid@ invitad@, no dude en registrarse!" end end end in ruby there is no multi inheritance but you can import modules into classes, helpers are modules that are auto imported to he views of a given controller by rails , it appears you have deleted the module declaration inside the helper or you have placed the function outside the module declaration , in any case is if it still does not work please post the code in your helper. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 06/12/2011 01:58 AM, radhames brito wrote:> please confirm that the code in the helper is like this > > module HomeHelper > > def hi > if user_signed_in? > return "¡Bienvenid@ #{current_user.username} a nuestra web!" > else > return "¡Bienvenid@ invitad@, no dude en registrarse!" > end > end > > end > > in ruby there is no multi inheritance but you can import modules into > classes, helpers are modules that are auto imported to he views of a > given controller by rails , it appears you have deleted the module > declaration inside the helper or you have placed the function outside > the module declaration , in any case is if it still does not work > please post the code in your helper. > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en.Oh, thanks. I understand the code and work with the result that I want. Thanks again, Radhames. With this problem I have learned things about the helpers and the way to work with its and the controllers. Thanks also for the rest of the users who tried to help me. Rewards, Ivan -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.