验证时出现语法错误! (一个月Rails课程麻烦)!

时间:2014-01-07 02:44:31

标签: ruby-on-rails ruby ruby-on-rails-3

我正在做一个月的测试,并且遇到了关于上传图钉的教程,这是我输入的内容(正如视频所说的那样)

class Pin < ActiveRecord::Base
  attr_accessible :description, :image

  validates :description, presence: true
  validates :user_id, presence: true
  validates_attachment :image, presence: true,
                content_type: { content_type: ['image/jpeg', 'image/jpg', 'image/png', 'image/gif'] },
                size: {less_than 5.megabytes}
  belongs_to :user
  has_attached_file :image 
end

我把它放在localhost:3000上,结果是:

syntax error, unexpected tINTEGER, expecting keyword_do or '{' or '(' size: {less_than 5.megabytes} ^ /Users/code/omrails/app/models/pin.rb:8: syntax error, unexpected '}', expecting keyword_end

我遵循了语法错误,但仍然无效。最后删除了逗号并且没有工作。现在已经挣扎了好几个小时,也无法在网站上找到类似的东西。抱歉,这个菜鸟问题。谢谢你的回复! :)

1 个答案:

答案 0 :(得分:1)

less_than应该是key

尝试:

validates_attachment :image, presence: true,
  content_type: { content_type: ['image/jpeg', 'image/jpg', 'image/png', 'image/gif'] },
  size: {less_than: 5.megabytes}