【问题标题】:Carrierwave and MiniMagick - images not uploadingCarrierwave 和 MiniMagick - 图片未上传
【发布时间】:2023-03-26 19:22:02
【问题描述】:

我有一个在 Nitrous.io 上运行的应用程序,安装了 Ruby 2 和 Rails 4.0。

我安装了carrierwave 和Mini_magick gem,但我的图片似乎仍然没有上传。

我有以下设置:

profile_uploader.rb

class ProfileUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick

  storage :file

  def store_dir
      "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

end

模型 - list.rb

class List < ActiveRecord::Base
  mount_uploader :profile, ProfileUploader
end

新建.html.haml

= form_for @list, :html => {:multipart => true} do |f|

  .field
    = f.label :name
    = f.text_field :name

  .field
    = f.label :telephone
    = f.text_field :telephone

  .field
    = f.label :Profile_image
    = f.file_field :profile 
    = f.hidden_field :profile_cache

  = f.submit

= link_to 'Back', lists_path

真的无法弄清楚为什么这不起作用,因为我相信一切都设置正确。人们可以提供的任何帮助都会很棒!

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 carrierwave minimagick


    【解决方案1】:

    所以事实证明,在我的控制器中,我有以下内容:

    def create
        @list = List.new(list_params)
        if @list.save
          redirect_to lists_path
        else
          render 'lists#new'
        end
    end
    ....
    
    def list_params
        params.require(:list).permit(:name, :telephone)
    end
    

    我将 :profile 添加到 list_params 定义后,它就开始工作了 :)

    【讨论】:

      猜你喜欢
      • 2015-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-24
      相关资源
      最近更新 更多