hubfub
asked on
Show current year in Ruby .erb
How do i get ruby to display the current year ie "2010" in a .erb file?
ASKER
that didn't work
Ah, yes... sorry:
<%= "#{Date.now.year}" %>
I tested the basic code (Date.now.year) if plain old ruby
<%= "#{Date.now.year}" %>
I tested the basic code (Date.now.year) if plain old ruby
So what result did you get when you tried the code?
If you're in straight ol' ruby (i.e., without Rails) then you have put a
require 'date'
at the beginning of your code so that you get the date modules... that's what I did and it works for me.
If you're in straight ol' ruby (i.e., without Rails) then you have put a
require 'date'
at the beginning of your code so that you get the date modules... that's what I did and it works for me.
ASKER
Doesnt work
Showing app/views/shared/_footer.h tml.erb where line #46 raised:
private method `now' called for Date:Class
Extracted source (around line #46):
43: </div>
44: <div id="subfooter">
45: <div class="container clearfix">
46: Use of this website constitutes acceptance of our <a href="/legal/terms-and-con ditions">T erms and Conditions</a>. We care about your <a href="/legal/privacy-polic y">Privacy </a>.<br />© <%= "#{Date.now.year}" %> Pick A Quote Pty Ltd.
47: </div>
48: </div>
Trace of template inclusion: app/views/layouts/applicat ion.html.e rb
RAILS_ROOT: /home/hubfub/rails-app/pic kaquote
It's ruby on rails
Showing app/views/shared/_footer.h
private method `now' called for Date:Class
Extracted source (around line #46):
43: </div>
44: <div id="subfooter">
45: <div class="container clearfix">
46: Use of this website constitutes acceptance of our <a href="/legal/terms-and-con
47: </div>
48: </div>
Trace of template inclusion: app/views/layouts/applicat
RAILS_ROOT: /home/hubfub/rails-app/pic
It's ruby on rails
OK... Make it DateTime.now.year -- I just tried that in a sample rails app
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<%= Date.now.year %>