rails 4.0.0
先安装了gem carrierwave
执行了rails g uploader Photo ,rails g migration AddPhotoToUsers photo:string
user.rb 模型里面加了
attr_accessible :title, :content, :photo
mount_uploader :photo, PhotoUploader
视图里面也加了
<%= form_for @user, html: {multipart: true } do |f| %>
<%= f.file_field :photo %>
<%= f.hidden_field :photo_cache %>
可是在显示页面显示不出来
<%= image_tag(@user.photo_url) %>
日志里面是这样的
Processing by UserController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"Nb9oB7AiU0Xlv2DQPf++M1XSwmE4QZJ1Bw6vMkrgMlU=", "product"=>{"title"=>"", "photo"=>#<ActionDispatch::Http::UploadedFile:0xb4d7a938 @tempfile=#<Tempfile:/tmp/RackMultipart20130629-3375-14v9nwb>, @original_filename="91ef76c6a7efce1beb91eb76ae51f3deb58f65d7.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"user[photo]\"; filename=\"91ef76c6a7efce1beb91eb76ae51f3deb58f65d7.jpg\"\r\nContent-Type: image/jpeg\r\n">, "photo_cache"=>"", "content"=>"", "price"=>""}, "commit"=>"Create User"}
Unpermitted parameters: photo, photo_cache
Rail4 用脚手架生成的代码会添加好访问属性
另外加进来的数据要添加到控制器最下面的方法那里
def product_params