2014-04-08 70 views
4

我需要上传图像到我的filme收集应用 我使用carrierwave做到这一点(follows the railscasts stepsCarrierWave文件上传不在轨道

第1步我添加宝石“carrierwave”工作,“〜> 0.9”我的Gemfile然后运行束 步骤2导轨克载图像然后导轨耙分贝 步骤3导轨克迁移add_image_to_filmes图像后克支架filmes名称moviestype:字符串,然后耙分贝

其它步骤是相同railscasts在

我的电影模式

attr_accessible :name, :moviestype, :image 
    mount_uploader :image, ImageUploader 

在我_form.html.erb

<%= form_for @filme, :html => {:multipart => true} do |f| %> 
    <% if @filme.errors.any? %> 
    <div id="error_explanation"> 
     <h2><%= pluralize(@filme.errors.count, "error") %> prohibited this filme from being saved:</h2> 

     <ul> 
     <% @filme.errors.full_messages.each do |msg| %> 
     <li><%= msg %></li> 
     <% end %> 
     </ul> 
    </div> 
    <% end %> 

    <div class="field"> 
    <%= f.label :name %><br> 
    <%= f.text_field :name %> 
    </div> 
    <div class="field"> 
    <%= f.label :moviestype %><br> 
    <%= f.text_field :moviestype %> 
    </div> 
    <div class="field"> 
    <br> 
    <%= f.file_field :image %> 
    </div> 

    <div class="actions"> 
    <%= f.submit %> 
    </div> 
<% end %> 

在show.html.erb

<p id="notice"><%= notice %></p> 

<p> 
    <strong>Name:</strong> 
    <%= @filme.name %> 
</p> 

<p> 
    <strong>Moviestype:</strong> 
    <%= @filme.moviestype %> 
</p> 
<%= image_tag @filme.image_url(:thumb) if @filme.image? %> 

<%= link_to 'Edit', edit_filme_path(@filme) %> | 
<%= link_to 'Back', filmes_path %> 

问题是,它没有上传任何图片,但是电影名称和其他字段插入db.how我可以解决这个问题吗?需要快速帮助。

+0

请分享在提交表单生成的服务器日志。 –

+0

https://www.dropbox.com/s/zxtoh9olabn4jzy/log.txt –

+0

你有没有:图片白名单?你的控制器里有一个方法来指定可以上传的内容吗?可能看起来像这样... params.require(:filme).permit(:name,:moviestype)...在这种情况下,您需要添加:image(和:image_cache,最终) – SteveTurczyn

回答

3

根据错误日志,您不允许image保存在数据库中。 在你FilmesController,你需要允许:image作为

def filme_params 
    params.require(:filme).permit(:name, :moviestype, :image) ## Add :image attribute 
end 
+0

这是我的控制器https:/ /www.dropbox.com/s/ih54m4pk6y9vsfz/filmes_controller.rb –

+0

您错过了:image属性。看到我更新的答案。 –

+0

工作谢谢 –