getting the current date in Rails Model

datetime, ruby, ruby-on-rails

Solution

Try:

Paperclip.interpolates :prefix  do |attachment, style|
  "#{Date.today.to_s}/#{attachment.instance.image_file_name}"
end 

Problem

Im trying to get the current date inside my rails model like this: Inside Photo.rb ``` Paperclip.interpolates :prefix do |attachment, style| :today_date => Date.today.to_s "#{:today_date}/#{attachment.instance.image_file_name}" end ``` When I send a Photo to the server from the client I get an error and the following console output on the server. This tells me that there is a problem with the "Date" function Server Console: ``` Started POST "/photos.json" for 127.0.0.1 at 2013-02-20 13:47:35 -0800 13:47:35 web.1 | 13:47:35 web.1 | SyntaxError (/Users/AM/Documents/RailsWS/test/app/models/photo.rb:22: syntax error, unexpected tASSOC, expecting keyword_end 13:47:35 web.1 | :today_date => Date.today.to_s 13:47:35 web.1 | ^): 13:47:35 web.1 | app/controllers/photos_controller.rb:1:in `<top (required)>' ``` What am I doing wrong? How do I get the current date into this variable? Thanks

Original source