<%= ... if logged_in? %>
<%= ... if logged_in? %>
var CurrentUser = {
loggedIn: false,
author: false,
admin: false,
init: function() {
this.loggedIn = Cookie.get('token') != null;
this.admin = Cookie.get('admin') != null;
}
};
var Application = {
init: function() {
CurrentUser.init();
},
onBodyLoaded: function() {
if (CurrentUser.loggedIn) {
$$('.if_logged_in').invoke('show');
$$('.unless_logged_in').invoke('hide');
}
if (CurrentUser.admin) {
$$('.if_admin').invoke('show');
}
}
};
<%= flash[:notice] %>
. However, this is not a problem, there is a great plugin Cacheable Flash.ruby script/plugin install svn://rubyforge.org/var/svn/pivotalrb/cacheable_flash/trunk
include CacheableFlash
flash[:notice] = "Welcome to Eternity" if current_user
<div id="error_div_id" class="flash flash_error"></div>
<div id="notice_div_id" class="flash flash_notice"></div>
ruby-json
, and replaced the line gem "json"
with gem "ruby-json"
in /vendor/plugins/cachable-flash/init.rb. And it all worked like a clock.Source: https://habr.com/ru/post/51042/
All Articles