Thanks, it works great. I knew it was something simple like that. I
have a follow-up, though. I’d like to insert current_user.login (the
name of the user) into a form when a user creates a recipe (it’s recipe
site I’m building). Here’s what I have now, but it doesn’t work:
<%= text_field ‘recipe’, ‘username’, current_user.login %>
Also, how do I make the text field hidden to the user, so they don’t
even see that it’s being recorded under their name; it just does it
Once again, I’m sure this is simple, but this is my first time doing any
sort of serious programming or web development, so little help like this
goes a long way for me.
Alex W. wrote:
Dave A. wrote:
Hi, I’m setting up a basic user authentication system and I don’t know
how to use the information that gets loaded into the session once a user
logs in. The session is session[:user], which I believe contains all of
the user information. I created a little shortcut for session[:user]
in my application.rb.
How do I call individual pieces of information out of that in my view?
Like if I wanted to display the current user’s username somewhere?
Let me know if more information is needed, but I assume this is kind of
a generic thing.
Thanks so much!
In a view you can just do:
<%= session[:user].username %>
And if you add to your application.rb that has the current_user method
Then your current_user method will be available in the view:
<%= current_user.username %>