Solved

Show current year in Ruby .erb

Posted on 2010-09-10
7
1,422 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
  • 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Choosing a Server-Side Scripting Language - Criterion 4 6 442
Ruby Rails form 4 270
ruby image 1 133
Merge XML files using a unique key? 8 106
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…
In Ruby, Call or invoke a API DLL library is easily via Win32API class, win32-api gem or other gems. For general DLL API call, there are quite a few references, some good tips list below: http://www.rubytips.org/2008/05/13/accessing-windows-api-fro…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

821 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