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

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

概述我试图在我的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里面

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

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

Server Console:

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

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

谢谢

解决方法 尝试:

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

以上是内存溢出为你收集整理的ruby-on-rails – 在Rails模型中获取当前日期全部内容,希望文章能够帮你解决ruby-on-rails – 在Rails模型中获取当前日期所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1290529.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-09
下一篇2022-06-09

发表评论

登录后才能评论

评论列表(0条)

    保存