Link to home
Start Free TrialLog in
Avatar of hubfub
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?
Avatar of JESii
JESii
Flag of United States of America image

Just use the year method of a date in your erb file; this will give you the current date's year:

<%= Date.now.year %>
Avatar of hubfub
hubfub

ASKER

that didn't work
Ah, yes... sorry:

<%= "#{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.
Avatar of hubfub

ASKER

Doesnt work

Showing app/views/shared/_footer.html.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-conditions">Terms and Conditions</a>. We care about your <a href="/legal/privacy-policy">Privacy</a>.<br />&copy; <%= "#{Date.now.year}" %> Pick A Quote Pty Ltd.
47:       </div>
48: </div>
Trace of template inclusion: app/views/layouts/application.html.erb

RAILS_ROOT: /home/hubfub/rails-app/pickaquote

It's ruby on rails
OK... Make it DateTime.now.year -- I just tried that in a sample rails app
ASKER CERTIFIED SOLUTION
Avatar of JESii
JESii
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial