Hi, I''m trying create a user system for a future project but I have a problem when I want give to my users the "Welcome". This is my code: #application_controller class ApplicationController < ActionController::Base protect_from_forgery helper_method :current_user private def current_user_session return @current_user_session if defined?(@current_user_session) @current_user_session = UserSession.find end def current_user @current_user = current_user_session && current_user_session.user end end #welcome_controller class WelcomeController < ApplicationController def hi @current_user if (@current_user) @welr = ''¡Bienvenido'' + @current_user + '' a nuestra web!'' else @weli = "¡Bienvenido invitado, no dude en registrarse!" end end end #user_sessions_controller class UserSessionsController < ApplicationController def new @user_session = UserSession.new end def create @user_session = UserSession.new(params[:user_session]) if @user_session.save flash[:notice] = "Estás dentro de nuestro sistema" redirect_to root_url else render :action => ''new'' end end def destroy @user_session = UserSession.find @user_session.destroy flash[:notice] = "Usted está fuera de nuestro sistema" redirect_to root_url end end #hi.html.erb <h1><%= @controller.hi %></h1> I believe that my problem are in the variable that I''m use, but I have tried with @user_session and nothing. Anyone know? 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.
On 9 Jun 2011, at 17:26, Distriker <ivanhcelrinconelmejor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, I''m trying create a user system for a future project but I have a > problem when I want give to my users the "Welcome". This is my code: > > #application_controller > class ApplicationController < ActionController::Base > protect_from_forgery > > helper_method :current_user > private > def current_user_session > return @current_user_session if defined?(@current_user_session) > @current_user_session = UserSession.find > end > def current_user > @current_user = current_user_session && current_user_session.user > end > end > > #welcome_controller > class WelcomeController < ApplicationController > def hi > @current_user > if (@current_user) > @welr = ''¡Bienvenido'' + @current_user + '' a nuestra web!'' > else > @weli = "¡Bienvenido invitado, no dude en registrarse!" > end > end > end > > # > #hi.html.erb > <h1><%= @controller.hi %></h1> > > I believe that my problem are in the variable that I''m use, but I have > tried with @user_session and nothing. >Assuming you want to display the text stored in @weli then you should be doing <%= @weli %> Fred> Anyone know? > > 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. >-- 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/09/2011 06:13 PM, Frederick Cheung wrote:> On 9 Jun 2011, at 17:26, Distriker<ivanhcelrinconelmejor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Hi, I''m trying create a user system for a future project but I have a >> problem when I want give to my users the "Welcome". This is my code: >> >> #application_controller >> class ApplicationController< ActionController::Base >> protect_from_forgery >> >> helper_method :current_user >> private >> def current_user_session >> return @current_user_session if defined?(@current_user_session) >> @current_user_session = UserSession.find >> end >> def current_user >> @current_user = current_user_session&& current_user_session.user >> end >> end >> >> #welcome_controller >> class WelcomeController< ApplicationController >> def hi >> @current_user >> if (@current_user) >> @welr = ''¡Bienvenido'' + @current_user + '' a nuestra web!'' >> else >> @weli = "¡Bienvenido invitado, no dude en registrarse!" >> end >> end >> end >> >> # >> #hi.html.erb >> <h1><%= @controller.hi %></h1> >> >> I believe that my problem are in the variable that I''m use, but I have >> tried with @user_session and nothing. >> > Assuming you want to display the text stored in @weli then you should be doing<%= @weli %> > > Fred >> Anyone know? >> >> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >>Hi Fred, I want show @weli to my guest and @welr to my users, that is why I use "if" and the variable @current_user, but, does not works. Regars, /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.
On 9 Jun 2011, at 18:31, Iván Hernández <ivanhcelrinconelmejor-Re5JQEeQqe8@public.gmane.orgm> wrote:> On 06/09/2011 06:13 PM, Frederick Cheung wrote: >> >> On 9 Jun 2011, at 17:26, Distriker <ivanhcelrinconelmejor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> Hi, I''m trying create a user system for a future project but I have a >>> problem when I want give to my users the "Welcome". This is my code: >>> >>> #application_controller >>> class ApplicationController < ActionController::Base >>> protect_from_forgery >>> >>> helper_method :current_user >>> private >>> def current_user_session >>> return @current_user_session if defined?(@current_user_session) >>> @current_user_session = UserSession.find >>> end >>> def current_user >>> @current_user = current_user_session && current_user_session.user >>> end >>> end >>> >>> #welcome_controller >>> class WelcomeController < ApplicationController >>> def hi >>> @current_user >>> if (@current_user) >>> @welr = ''¡Bienvenido'' + @current_user + '' a nuestra web!'' >>> else >>> @weli = "¡Bienvenido invitado, no dude en registrarse!" >>> end >>> end >>> end >>> >>> # >>> #hi.html.erb >>> <h1><%= @controller.hi %></h1> >>> >>> I believe that my problem are in the variable that I''m use, but I have >>> tried with @user_session and nothing. >>> >> Assuming you want to display the text stored in @weli then you should be doing <%= @weli %> >> >> Fred >>> Anyone know? >>> >>> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >>> >> > Hi Fred, I want show @weli to my guest and @welr to my users, that is why I use "if" and the variable @current_user, but, does not works. >Use current_user - you are only setting @current_user when current_user is called. Fred.> Regars, 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.-- 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/09/2011 07:04 PM, Frederick Cheung wrote:> > > On 9 Jun 2011, at 18:31, Iván Hernández > <ivanhcelrinconelmejor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > <mailto:ivanhcelrinconelmejor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> wrote: > >> On 06/09/2011 06:13 PM, Frederick Cheung wrote: >>> On 9 Jun 2011, at 17:26, Distriker<ivanhcelrinconelmejor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <mailto:ivanhcelrinconelmejor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> wrote: >>> >>>> Hi, I''m trying create a user system for a future project but I have a >>>> problem when I want give to my users the "Welcome". This is my code: >>>> >>>> #application_controller >>>> class ApplicationController< ActionController::Base >>>> protect_from_forgery >>>> >>>> helper_method :current_user >>>> private >>>> def current_user_session >>>> return @current_user_session if defined?(@current_user_session) >>>> @current_user_session = UserSession.find >>>> end >>>> def current_user >>>> @current_user = current_user_session&& current_user_session.user >>>> end >>>> end >>>> >>>> #welcome_controller >>>> class WelcomeController< ApplicationController >>>> def hi >>>> @current_user >>>> if (@current_user) >>>> @welr = ''¡Bienvenido'' + @current_user + '' a nuestra web!'' >>>> else >>>> @weli = "¡Bienvenido invitado, no dude en registrarse!" >>>> end >>>> end >>>> end >>>> >>>> # >>>> #hi.html.erb >>>> <h1><%= @controller.hi %></h1> >>>> >>>> I believe that my problem are in the variable that I''m use, but I have >>>> tried with @user_session and nothing. >>>> >>> Assuming you want to display the text stored in @weli then you should be doing<%= @weli %> >>> >>> Fred >>>> Anyone know? >>>> >>>> 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 torubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>. >>>> To unsubscribe from this group, send email torubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <mailto:rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>. >>>> For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. >>>> >> Hi Fred, I want show @weli to my guest and @welr to my users, that is >> why I use "if" and the variable @current_user, but, does not works. >> > Use current_user - you are only setting @current_user when > current_user is called. > > Fred. >> 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org >> <mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>. >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org >> <mailto:rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en.Ok, thanks, before If I changed all my @current_user in /welcome_controller/ the webpage show me an error: can''t convert User into String But I just noticed the error, and it was because User must be converted in String with /.to_s/, what I was silly :( One question more, now, this show me the welcome message correct but no with the username, but with this: <User:0xb6cd90f4> How I can change it? 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.
On Jun 9, 2011, at 2:17 PM, Iván Hernández wrote:> On 06/09/2011 07:04 PM, Frederick Cheung wrote: >> >> >> >> On 9 Jun 2011, at 18:31, Iván Hernández <ivanhcelrinconelmejor@gmail.com >> > wrote: >> >>> On 06/09/2011 06:13 PM, Frederick Cheung wrote: >>>> >>>> On 9 Jun 2011, at 17:26, Distriker >>>> <ivanhcelrinconelmejor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>> >>>>> Hi, I''m trying create a user system for a future project but I >>>>> have a >>>>> problem when I want give to my users the "Welcome". This is my >>>>> code: >>>>> >>>>> #application_controller >>>>> class ApplicationController < ActionController::Base >>>>> protect_from_forgery >>>>> >>>>> helper_method :current_user >>>>> private >>>>> def current_user_session >>>>> return @current_user_session if defined?(@current_user_session) >>>>> @current_user_session = UserSession.find >>>>> end >>>>> def current_user >>>>> @current_user = current_user_session && >>>>> current_user_session.user >>>>> end >>>>> end >>>>> >>>>> #welcome_controller >>>>> class WelcomeController < ApplicationController >>>>> def hi >>>>> @current_user >>>>> if (@current_user) >>>>> @welr = ''¡Bienvenido'' + @current_user + '' a nuestra web!'' >>>>> else >>>>> @weli = "¡Bienvenido invitado, no dude en registrarse!" >>>>> end >>>>> end >>>>> end >>>>> >>>>> # >>>>> #hi.html.erb >>>>> <h1><%= @controller.hi %></h1> >>>>> >>>>> I believe that my problem are in the variable that I''m use, but >>>>> I have >>>>> tried with @user_session and nothing. >>>>> >>>> Assuming you want to display the text stored in @weli then you >>>> should be doing <%= @weli %> >>>> >>>> Fred >>>>> Anyone know? >>>>> >>>>> 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-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm >>>>> . >>>>> 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 >>>>> . >>>>> >>> Hi Fred, I want show @weli to my guest and @welr to my users, that >>> is why I use "if" and the variable @current_user, but, does not >>> works. >>> >> Use current_user - you are only setting @current_user when >> current_user is called. >> >> Fred. >>> 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-/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 >>> . >> -- >> 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 >> . > Ok, thanks, before If I changed all my @current_user in > welcome_controller the webpage show me an error: > can''t convert User into String > But I just noticed the error, and it was because User must be > converted in String with .to_s, what I was silly :( > > One question more, now, this show me the welcome message correct but > no with the username, but with this: > <User:0xb6cd90f4> > How I can change it?What is the name of the attribute on User that holds the name? If it''s called name, then you would do @current_user.name in your erb block. Walter -- 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/09/2011 07:23 PM, Walter Davis wrote:> > On Jun 9, 2011, at 2:17 PM, Iván Hernández wrote: > >> On 06/09/2011 07:04 PM, Frederick Cheung wrote: >>> >>> >>> >>> On 9 Jun 2011, at 18:31, Iván Hernández >>> <ivanhcelrinconelmejor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>>> On 06/09/2011 06:13 PM, Frederick Cheung wrote: >>>>> >>>>> On 9 Jun 2011, at 17:26, Distriker >>>>> <ivanhcelrinconelmejor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>>> >>>>>> Hi, I''m trying create a user system for a future project but I >>>>>> have a >>>>>> problem when I want give to my users the "Welcome". This is my code: >>>>>> >>>>>> #application_controller >>>>>> class ApplicationController < ActionController::Base >>>>>> protect_from_forgery >>>>>> >>>>>> helper_method :current_user >>>>>> private >>>>>> def current_user_session >>>>>> return @current_user_session if defined?(@current_user_session) >>>>>> @current_user_session = UserSession.find >>>>>> end >>>>>> def current_user >>>>>> @current_user = current_user_session && current_user_session.user >>>>>> end >>>>>> end >>>>>> >>>>>> #welcome_controller >>>>>> class WelcomeController < ApplicationController >>>>>> def hi >>>>>> @current_user >>>>>> if (@current_user) >>>>>> @welr = ''¡Bienvenido'' + @current_user + '' a nuestra web!'' >>>>>> else >>>>>> @weli = "¡Bienvenido invitado, no dude en registrarse!" >>>>>> end >>>>>> end >>>>>> end >>>>>> >>>>>> # >>>>>> #hi.html.erb >>>>>> <h1><%= @controller.hi %></h1> >>>>>> >>>>>> I believe that my problem are in the variable that I''m use, but I >>>>>> have >>>>>> tried with @user_session and nothing. >>>>>> >>>>> Assuming you want to display the text stored in @weli then you >>>>> should be doing <%= @weli %> >>>>> >>>>> Fred >>>>>> Anyone know? >>>>>> >>>>>> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>>>>> For more options, visit this group at >>>>>> http://groups.google.com/group/rubyonrails-talk?hl=en. >>>>>> >>>> Hi Fred, I want show @weli to my guest and @welr to my users, that >>>> is why I use "if" and the variable @current_user, but, does not works. >>>> >>> Use current_user - you are only setting @current_user when >>> current_user is called. >>> >>> Fred. >>>> 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-/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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> For more options, visit this group at >>> http://groups.google.com/group/rubyonrails-talk?hl=en. >> Ok, thanks, before If I changed all my @current_user in >> welcome_controller the webpage show me an error: >> can''t convert User into String >> But I just noticed the error, and it was because User must be >> converted in String with .to_s, what I was silly :( >> >> One question more, now, this show me the welcome message correct but >> no with the username, but with this: >> <User:0xb6cd90f4> >> How I can change it? > > What is the name of the attribute on User that holds the name? If it''s > called name, then you would do @current_user.name in your erb block. > > Walter >Hi Walter, I think that it''s current_user_session.user, but this don''t work, because show me the same. I''m trying make a call or something, but nothing. 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.
On Jun 10, 2011, at 12:33 PM, Iván Hernández wrote:> On 06/09/2011 07:23 PM, Walter Davis wrote: >> >> On Jun 9, 2011, at 2:17 PM, Iván Hernández wrote: >> >>> On 06/09/2011 07:04 PM, Frederick Cheung wrote: >>>> >>>> >>>> >>>> On 9 Jun 2011, at 18:31, Iván Hernández <ivanhcelrinconelmejor@gmail.com >>>> > wrote: >>>> >>>>> On 06/09/2011 06:13 PM, Frederick Cheung wrote: >>>>>> >>>>>> On 9 Jun 2011, at 17:26, Distriker <ivanhcelrinconelmejor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org >>>>>> > wrote: >>>>>> >>>>>>> Hi, I''m trying create a user system for a future project but I >>>>>>> have a >>>>>>> problem when I want give to my users the "Welcome". This is my >>>>>>> code: >>>>>>> >>>>>>> #application_controller >>>>>>> class ApplicationController < ActionController::Base >>>>>>> protect_from_forgery >>>>>>> >>>>>>> helper_method :current_user >>>>>>> private >>>>>>> def current_user_session >>>>>>> return @current_user_session if defined? >>>>>>> (@current_user_session) >>>>>>> @current_user_session = UserSession.find >>>>>>> end >>>>>>> def current_user >>>>>>> @current_user = current_user_session && >>>>>>> current_user_session.user >>>>>>> end >>>>>>> end >>>>>>> >>>>>>> #welcome_controller >>>>>>> class WelcomeController < ApplicationController >>>>>>> def hi >>>>>>> @current_user >>>>>>> if (@current_user) >>>>>>> @welr = ''¡Bienvenido'' + @current_user + '' a nuestra web!'' >>>>>>> else >>>>>>> @weli = "¡Bienvenido invitado, no dude en registrarse!" >>>>>>> end >>>>>>> end >>>>>>> end >>>>>>> >>>>>>> # >>>>>>> #hi.html.erb >>>>>>> <h1><%= @controller.hi %></h1> >>>>>>> >>>>>>> I believe that my problem are in the variable that I''m use, >>>>>>> but I have >>>>>>> tried with @user_session and nothing. >>>>>>> >>>>>> Assuming you want to display the text stored in @weli then you >>>>>> should be doing <%= @weli %> >>>>>> >>>>>> Fred >>>>>>> Anyone know? >>>>>>> >>>>>>> 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@googlegroups.com >>>>>>> . >>>>>>> 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 >>>>>>> . >>>>>>> >>>>> Hi Fred, I want show @weli to my guest and @welr to my users, >>>>> that is why I use "if" and the variable @current_user, but, does >>>>> not works. >>>>> >>>> Use current_user - you are only setting @current_user when >>>> current_user is called. >>>> >>>> Fred. >>>>> 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-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm >>>>> . >>>>> 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 >>>>> . >>>> -- >>>> 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 >>>> . >>> Ok, thanks, before If I changed all my @current_user in >>> welcome_controller the webpage show me an error: >>> can''t convert User into String >>> But I just noticed the error, and it was because User must be >>> converted in String with .to_s, what I was silly :( >>> >>> One question more, now, this show me the welcome message correct >>> but no with the username, but with this: >>> <User:0xb6cd90f4> >>> How I can change it? >> >> What is the name of the attribute on User that holds the name? If >> it''s called name, then you would do @current_user.name in your erb >> block. >> >> Walter >> > Hi Walter, I think that it''s current_user_session.user, but this > don''t work, because show me the same. I''m trying make a call or > something, but nothing. > > Regards, Iván >current_user_session.user gets you the current instance of the User model, so you need to look inside that for the name attribute. If it''s called first_name, for example, then you would use current_user_session.user.first_name as your value. If it''s called name, then change first_name to name. You want the value of a specific property of that instance object, not the object itself. That''s the part you''ve been chasing your tail about here. Walter> -- > 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 > . >-- 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/10/2011 06:14 PM, Walter Davis wrote:> > On Jun 10, 2011, at 12:33 PM, Iván Hernández wrote: > >> On 06/09/2011 07:23 PM, Walter Davis wrote: >>> >>> On Jun 9, 2011, at 2:17 PM, Iván Hernández wrote: >>> >>>> On 06/09/2011 07:04 PM, Frederick Cheung wrote: >>>>> >>>>> >>>>> >>>>> On 9 Jun 2011, at 18:31, Iván Hernández >>>>> <ivanhcelrinconelmejor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>>> >>>>>> On 06/09/2011 06:13 PM, Frederick Cheung wrote: >>>>>>> >>>>>>> On 9 Jun 2011, at 17:26, Distriker >>>>>>> <ivanhcelrinconelmejor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>>>>> >>>>>>>> Hi, I''m trying create a user system for a future project but I >>>>>>>> have a >>>>>>>> problem when I want give to my users the "Welcome". This is my >>>>>>>> code: >>>>>>>> >>>>>>>> #application_controller >>>>>>>> class ApplicationController < ActionController::Base >>>>>>>> protect_from_forgery >>>>>>>> >>>>>>>> helper_method :current_user >>>>>>>> private >>>>>>>> def current_user_session >>>>>>>> return @current_user_session if defined?(@current_user_session) >>>>>>>> @current_user_session = UserSession.find >>>>>>>> end >>>>>>>> def current_user >>>>>>>> @current_user = current_user_session && >>>>>>>> current_user_session.user >>>>>>>> end >>>>>>>> end >>>>>>>> >>>>>>>> #welcome_controller >>>>>>>> class WelcomeController < ApplicationController >>>>>>>> def hi >>>>>>>> @current_user >>>>>>>> if (@current_user) >>>>>>>> @welr = ''¡Bienvenido'' + @current_user + '' a nuestra web!'' >>>>>>>> else >>>>>>>> @weli = "¡Bienvenido invitado, no dude en registrarse!" >>>>>>>> end >>>>>>>> end >>>>>>>> end >>>>>>>> >>>>>>>> # >>>>>>>> #hi.html.erb >>>>>>>> <h1><%= @controller.hi %></h1> >>>>>>>> >>>>>>>> I believe that my problem are in the variable that I''m use, but >>>>>>>> I have >>>>>>>> tried with @user_session and nothing. >>>>>>>> >>>>>>> Assuming you want to display the text stored in @weli then you >>>>>>> should be doing <%= @weli %> >>>>>>> >>>>>>> Fred >>>>>>>> Anyone know? >>>>>>>> >>>>>>>> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>>>>>>> For more options, visit this group at >>>>>>>> http://groups.google.com/group/rubyonrails-talk?hl=en. >>>>>>>> >>>>>> Hi Fred, I want show @weli to my guest and @welr to my users, >>>>>> that is why I use "if" and the variable @current_user, but, does >>>>>> not works. >>>>>> >>>>> Use current_user - you are only setting @current_user when >>>>> current_user is called. >>>>> >>>>> Fred. >>>>>> 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-/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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>>>> For more options, visit this group at >>>>> http://groups.google.com/group/rubyonrails-talk?hl=en. >>>> Ok, thanks, before If I changed all my @current_user in >>>> welcome_controller the webpage show me an error: >>>> can''t convert User into String >>>> But I just noticed the error, and it was because User must be >>>> converted in String with .to_s, what I was silly :( >>>> >>>> One question more, now, this show me the welcome message correct >>>> but no with the username, but with this: >>>> <User:0xb6cd90f4> >>>> How I can change it? >>> >>> What is the name of the attribute on User that holds the name? If >>> it''s called name, then you would do @current_user.name in your erb >>> block. >>> >>> Walter >>> >> Hi Walter, I think that it''s current_user_session.user, but this >> don''t work, because show me the same. I''m trying make a call or >> something, but nothing. >> >> Regards, Iván >> > > current_user_session.user gets you the current instance of the User > model, so you need to look inside that for the name attribute. If it''s > called first_name, for example, then you would use > current_user_session.user.first_name as your value. If it''s called > name, then change first_name to name. You want the value of a specific > property of that instance object, not the object itself. That''s the > part you''ve been chasing your tail about here. > > Walter > >> -- >> 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. >> >Yes, it''s really, I had not been ocurred, I am silly, sorry. Very thanks for all the reply and the support provided. Thanks Fred, thanks Walter. 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.