Solved

Show current year in Ruby .erb

Posted on 2010-09-10
7
1,436 Views
Last Modified: 2013-11-13
How do i get ruby to display the current year ie "2010" in a .erb file?
0
Comment
Question by:hubfub
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 12

Expert Comment

by:JESii
ID: 33651503
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
 
LVL 1

Author Comment

by:hubfub
ID: 33651660
that didn't work
0
 
LVL 12

Expert Comment

by:JESii
ID: 33651723
Ah, yes... sorry:

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

I tested the basic code (Date.now.year) if plain old ruby
0
Independent Software Vendors: 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!

 
LVL 12

Expert Comment

by:JESii
ID: 33652178
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
 
LVL 1

Author Comment

by:hubfub
ID: 33659772
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
 
LVL 12

Expert Comment

by:JESii
ID: 33660831
OK... Make it DateTime.now.year -- I just tried that in a sample rails app
0
 
LVL 12

Accepted Solution

by:
JESii earned 500 total points
ID: 33660840
And you don't need the quotes and interpolation (the #{...} part). You can just make it:
   <%= DateTime.now.year %>

Whew!
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
rails 2.3.x link_to tag 1 500
trying to get text between certain words 6 222
Ruby 2-D array 1 198
Javascript: handler for multi-select dropdown 8 176
I recently rediscovered rails when I needed a holiday project and decided to build a management dashboard for the company where I work.  With it being a project done in my free time, I could focus my time on learning the basics rather than trying to…
Article by: narshlob
If you've ever programmed in Ruby and have come across either a proc or a lambda, you might have been wondering what the difference is between the two and when you would use one over the other. This article will try to explain the difference between…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question