I''m new to Rails and am modifying the ToDo tutorial app into something else. I have successfully installed authentication via login_generator and now I working toward restricting access to certain database records based on the login name. I realize that eventually, I''ll want to use the "id" field, but for now, I just want to use the user name itself. I have tried a number of things, including this in a view, just to see the value: <%= @session[''user''] %> But this is what I get: <User:0x14c0368> rather than the name the user entered at the login screen. What am I missing? How can I access the entered user name? Thanks! Tom ------------------------------------------------------------------------ ---- Tom Donovan Hawthorn School District 73 Mgr. of Tech. Systems, Webmaster Vernon Hills, IL ------------------------------------------------------------------------ ----
On Sun, Mar 06, 2005 at 04:25:58PM -0600, Tom Donovan wrote:> I''m new to Rails and am modifying the ToDo tutorial app into something > else. I have successfully installed authentication via login_generator > and now I working toward restricting access to certain database records > based on the login name. I realize that eventually, I''ll want to use > the "id" field, but for now, I just want to use the user name itself. > > I have tried a number of things, including this in a view, just to see > the value: > > <%= @session[''user''] %> > > But this is what I get: > > <User:0x14c0368> > > rather than the name the user entered at the login screen. What am I > missing? How can I access the entered user name?The session is carrying around an Active Record instance that corresponds to the record for the logged in user. What @session[''user''] returns is the actual object. If, for example, the table had a user_name field then you''d access that from the object by calling it''s user_name method. <%= @session[''user''].user_name %> marcel -- Marcel Molina Jr. <marcel-WRrfy3IlpWYdnm+yROfE0A@public.gmane.org>
> <%= @session[''user''].user_name %>I believe the field used by the User model in login_generator is login. So you are probably looking for <%= @session[''user''].login %> Good Luck -Brandon On 17:32 Sun 06 Mar , Marcel Molina Jr. wrote:> On Sun, Mar 06, 2005 at 04:25:58PM -0600, Tom Donovan wrote: > > I''m new to Rails and am modifying the ToDo tutorial app into something > > else. I have successfully installed authentication via login_generator > > and now I working toward restricting access to certain database records > > based on the login name. I realize that eventually, I''ll want to use > > the "id" field, but for now, I just want to use the user name itself. > > > > I have tried a number of things, including this in a view, just to see > > the value: > > > > <%= @session[''user''] %> > > > > But this is what I get: > > > > <User:0x14c0368> > > > > rather than the name the user entered at the login screen. What am I > > missing? How can I access the entered user name? > > The session is carrying around an Active Record instance that corresponds > to the record for the logged in user. What @session[''user''] returns is > the actual object. If, for example, the table had a user_name field then > you''d access that from the object by calling it''s user_name method. > > <%= @session[''user''].user_name %> > > marcel > -- > Marcel Molina Jr. <marcel-WRrfy3IlpWYdnm+yROfE0A@public.gmane.org> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-- Brandon Philips brandon-CJG/fkoVOTIdnm+yROfE0A@public.gmane.org "Open minds. Open doors. Open source." - osuosl.org _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Sun, 6 Mar 2005 16:25:58 -0600, Tom Donovan <list-rails-jG4xwPahMbbXRl1jA4ceMJyrNiDsoR7y@public.gmane.org> wrote:> I have tried a number of things, including this in a view, just to see > the value: > > <%= @session[''user''] %> > > But this is what I get: > > <User:0x14c0368>Somebody else already answered your question, but I just wanted to chip in a useful tidbit. As you can see, trying to print @session[''user''] wasn''t very helpful. Next time you''re in this situation, try this instead: <%=h @session[''user''].inspect %> That will provide much more useful information. ;) -- One Guy With A Camera http://rbpark.ath.cx