I have a signin lightbox that needs to be shown when user is not logged in. The lightbox is pletely implemented in javascript, fancybox and uses rails partials for html.
I can see the cookie is set in chrome when logged in, but document.cookie
seems to return empty. The reason probably has been explained here
How do I achieve this in javascript / erb.
I have a signin lightbox that needs to be shown when user is not logged in. The lightbox is pletely implemented in javascript, fancybox and uses rails partials for html.
I can see the cookie is set in chrome when logged in, but document.cookie
seems to return empty. The reason probably has been explained here
How do I achieve this in javascript / erb.
Share Improve this question edited May 23, 2017 at 12:09 CommunityBot 11 silver badge asked Jun 3, 2012 at 6:10 ShaggyInjunShaggyInjun 2,9832 gold badges34 silver badges54 bronze badges 2- 4 Does anyone actually have a js-based answer for this, unlike both answers listed below? – lulalala Commented Jul 30, 2012 at 8:24
- Probably impossible. See stackoverflow./a/29739169/6594668 or use cookies instead. – prograils Commented Apr 4, 2017 at 11:48
2 Answers
Reset to default 3Handle this in the backend. If you're doing this with rails, be sure to use and abuse current_user
, because it will be your best friend.
Then in your partial, you're free to have something like this
<% if current_user %>
<p>Wele <%= current_user.username %>!</p>
<% else %>
<p>Please <%= link_to 'sign in', login_path %></p>
<% end %>
Rails Sessions, Ruby on Rails Tutorial
same approach as Jordan Scales said, but making it simpler ... DRYing if @current_user.nil?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744287928a4566888.html
评论列表(0条)