以下是我的 model 配置,并已经可以通过 controller 上传到指定的目录,可就是打开数据库发现字段 img_path 和其他几个字段都是空的,只有 title 我输入的有内容,百度了一个早上还是没有解决,请大师们给看看。谢谢。 版本:rails3.2,paperclip 是最新版 环境:mac 和 windows 都不保存不了路径到数据库
#coding: utf-8
class Photo < ActiveRecord::Base
attr_accessible :img_path, :is_verify, :title
attr_accessor :img_path_file_name
attr_accessor :img_path_content_type
attr_accessor :img_path_file_size
attr_accessor :img_path_updated_at
has_attached_file :img_path,
:styles => {:thumb => "200x200>",:mini=>"100x100>",:medium => "400x400>",:large=> "600x600>"},
:default_url => "/images/:style/missing.png",
:url => "/uploads/pics/:id/:id_:style.:extension",
:path => ":rails_root/public/uploads/pics/:id/:id_:style.:extension"
validates_attachment_content_type :img_path, :content_type => [ 'image/gif', 'image/png', 'image/x-png', 'image/jpeg', 'image/pjpeg', 'image/jpg']
end
打开 log 有日志,发现插入的都为 nil:
INSERT INTO "photos" ("created_at", "img_path", "img_path_content_type", "img_path_file_name", "img_path_file_size", "img_path_updated_at", "is_verify", "title", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) [["created_at", Fri, 05 Jul 2013 11:22:48 CST +08:00], ["img_path", nil], ["img_path_content_type", nil], ["img_path_file_name", nil], ["img_path_file_size", nil], ["img_path_updated_at", nil], ["is_verify", nil], ["title", "vvvv"], ["updated_at", Fri, 05 Jul 2013 11:22:48 CST +08:00]]