Rails回形针的验证

时间:2015-01-05 12:49:22

标签: ruby-on-rails validation paperclip production

我使用回形针。我在家庭中有以下模型验证。在开发人员工作正常但在生产中不起作用。

class Family < ActiveRecord::Base
  has_many :products
  has_attached_file :image, styles: { original: "320x240", small: "64x64" }


  validates_presence_of :name, :description
  validates :image, :attachment_presence => true


  validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]
  validates_attachment_size :image, :less_than => 10.megabytes
  validates_attachment_size :image, :in => 0.megabytes..1.megabytes

end
  

I,[2015-01-05T07:45:11.091444#20474] INFO - :开始GET&#34; / families / new?locale = es&#34; for 88.20.141.138 at 2015-01-05 07:45:11 -0500   I,[2015-01-05T07:45:11.093468#20474]信息 - :由FamiliesController处理#new为HTML   I,[2015-01-05T07:45:11.093535#20474]信息 - :参数:{&#34; locale&#34; =&gt;&#34; es&#34;}   D,[2015-01-05T07:45:11.095564#20474] DEBUG - :用户负载(0.2ms)SELECT users。* FROM users WHERE users。{{1} } = 1 ORDER BY idusers ASC LIMIT 1   I,[2015-01-05T07:45:11.104610#20474]信息 - :渲染族/ _form.html.erb(3.7ms)   I,[2015-01-05T07:45:11.105000#20474]信息 - :在布局/应用程序中渲染族/ new.html.erb(6.1ms)   I,[2015-01-05T07:45:11.108690#20474]信息 - :渲染的布局/ _navigation.html.erb(1.9ms)   I,[2015-01-05T07:45:11.110200#20474]信息 - :渲染的布局/ _messages.html.erb(0.5ms)   I,[2015-01-05T07:45:11.110652#20474]信息 - :在17ms完成200 OK(浏览次数:13.6ms | ActiveRecord:0.2ms)   I,[2015-01-05T07:45:21.050016#20474]信息 - :开始POST&#34; /系列?locale = es&#34;在2015-01-05 07:45:21 -0500获得88.20.141.138   I,[2015-01-05T07:45:21.051441#20474]信息 - :由FamiliesController处理#create as HTML   I,[2015-01-05T07:45:21.051592#20474]信息 - :参数:{&#34; utf8&#34; =&gt;&#34;✓&#34;,&#34; authenticity_token&#34 ; =&gt;&#34; A1ieEMdwYcqAErWmQZF8WBf6lR0qMTTV5DS + r5LfPHsshWapnyEid6forMh / 18F5E + T / cW8J + yAacug5OcsxpQ ==&#34;,&#34; family&#34; =&gt; {&#34; name&#34; =&gt;& #34; fdgsgdf&#34;,&#34; description&#34; =&gt;&#34; sdfsdf&#34;,&#34; image&#34; =&gt;#,@ original_filename =&#34; ternera。 jpg&#34;,@ content_type =&#34; image / jpeg&#34;,@ headers =&#34; Content-Disposition:form-data;命名= \&#34;家庭[图像] \&#34 ;; filename = \&#34; ternera.jpg \&#34; \ r \ nConContent-Type:image / jpeg \ r \ n&#34;&gt;,&#34; active&#34; =&gt;&#34; 0&#34;},&#34;提交&#34; =&gt;&#34; Guardar&#34;,&#34;语言环境&#34; =&gt;&#34; es&#34;}   D,[2015-01-05T07:45:21.053404#20474] DEBUG - :用户负载(0.2ms)SELECT id。* FROM users WHERE users。{{1} } = 1 ORDER BY usersid ASC LIMIT 1   I,[2015-01-05T07:45:21.059186#20474]信息 - :在7ms内完成500内部服务器错误   F,[2015-01-05T07:45:21.060360#20474]致命 - :   NoMethodError(未定义的方法users创建&#39;

2 个答案:

答案 0 :(得分:2)

问题是parpeclip的版本和rails的版本。添加gem&#39; paperclip&#39;,&#34;〜&gt; 4.2&#34;到Gemfile运行捆绑安装。

more info

答案 1 :(得分:2)

如果你正在运行Rails 4.0+,请确保将'paperclip'gem文件更改为'〜&gt; 4.2'如建议的那样。这将是: 'paperclip','〜&gt; 4.2'