加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 在Rails模型中获取当前日期

发布时间:2020-12-17 03:04:48 所属栏目:百科 来源:网络整理
导读:我试图在我的rails模型中获取当前日期,如下所示: 在Photo.rb里面 Paperclip.interpolates :prefix do |attachment,style| :today_date = Date.today.to_s "#{:today_date}/#{attachment.instance.image_file_name}" end 当我从客户端向服务器发送照片时,我
我试图在我的rails模型中获取当前日期,如下所示:

在Photo.rb里面

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

当我从客户端向服务器发送照片时,我收到错误,并在服务器上输出以下控制台.这告诉我“日期”功能有问题

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)>'

我究竟做错了什么?如何将当前日期输入此变量?

谢谢

解决方法

尝试:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读