Solved

Show current year in Ruby .erb

Posted on 2010-09-10
7
1,414 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem with systems default Ruby version 2 670
Ruby Rails form 4 265
Help with Redmine installation on Ubuntu 14.04 6 288
Ruby - Extract Year from document text 6 108
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…
Recently I spent hours debugging an issue in a Rails project where ActiveRecord was causing MySQL errors trying to create a User object of a class at the top level of a Single Table Inheritance model structure.  It turns out `.create` behaves differ…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

803 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