簡體   English   中英

CarrierWave文件上傳在Rails中不起作用

[英]CarrierWave File Uploads not working in rails

我需要將圖像上傳到我的電影收藏應用程序中,我使用載波進行此操作( 遵循railscasts步驟

步驟1我將寶石'carrierwave','〜> 0.9'添加到我的Gemfile中,然后運行捆綁軟件步驟2在rake db后添加rails g上載器圖像,然后在rails g scaffold影片名稱中選擇movietype類型步驟3在rails g遷移中add_image_to_filmes image:string然后是rake db

其他步驟與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。如何解決此問題?需要快速幫助。

根據錯誤日志,您不允許將image保存在數據庫中。 FilmesController ,您需要允許:image

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM