• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1503
  • Last Modified:

Show current year in Ruby .erb

How do i get ruby to display the current year ie "2010" in a .erb file?
0
hubfub
Asked:
hubfub
  • 5
  • 2
1 Solution
 
JESiiCommented:
Just use the year method of a date in your erb file; this will give you the current date's year:

<%= Date.now.year %>
0
 
hubfubAuthor Commented:
that didn't work
0
 
JESiiCommented:
Ah, yes... sorry:

<%= "#{Date.now.year}" %>

I tested the basic code (Date.now.year) if plain old ruby
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
JESiiCommented:
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.
0
 
hubfubAuthor Commented:
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
0
 
JESiiCommented:
OK... Make it DateTime.now.year -- I just tried that in a sample rails app
0
 
JESiiCommented:
And you don't need the quotes and interpolation (the #{...} part). You can just make it:
   <%= DateTime.now.year %>

Whew!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now