Home selecting username using current_user in devise
Reply: 1

selecting username using current_user in devise

markets Published in 2017-11-29 21:20:17Z

I read that the helper current_user can be called in the view. So I have something like this

<h1> Customer id <%= User.select(:username).find(current_user).id %> </h1>

The equivalent of what I am trying to do in SQL is the following

SELECT username FROM users WHERE id = current_user

I am not sure what I am doing wrong. I'm getting this error message:

undefined local variable or method `current_user' for ApplicationController:Class

markets Reply to 2017-11-29 21:34:17Z

Since you have the current_user available from Devisegem, you have access to a User instance object, so you can do it directly by:

<h1>Customer id <%= current_user.username %></h1>

If you want to display the id:

<h1>Customer id <%= current_user.id %></h1>
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.333767 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO