On 06/11/2011 07:40 PM, radhames brito wrote:
On Sat, Jun 11, 2011 at 1:06 PM, Distriker
<[email protected]
<mailto:[email protected]>> 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 [email protected].
To unsubscribe from this group, send email to
[email protected].
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.