I want to display the current time (of the server) with Time.now
on all sites (different controllers).
Since the global displaying of headers/navigation bars and so on can be done within layout>application.html.erb I changed it to the following:
<!DOCTYPE html>
<html>
<head>
<title>Depot</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body class='<%= controller.controller_name %>'>
<nav>
<%= link_to 'Store', controller: 'store', action:'index' %>
<%= link_to 'Products', controller: 'products', action: 'index' %>
<span>Current time: <%= @time %></span>
<%= yield %>
</body>
</html>
Now I further hoped to possibly add the code to get the current time within the application_controller.rb. Here's the code I have in there
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
@time = Time.now
end
Unfortunately that's not working and I have to add the @time = Time.now - code within the controller (and method) I am using. This means I'd have to fill the code in several times and isn't that against the rails - idea?
I'd appreciate any help :)