开发者

Issues with Carrierwave in Rails 3.1.0

开发者 https://www.devze.com 2023-04-06 01:04 出处:网络
I\'m trying to attach a file \"attachment\" to my upload model.The attachment field in my db after creation is nil, and links link @upload.attachment.url just redirect to a parent object.Maybe I\'m do

I'm trying to attach a file "attachment" to my upload model. The attachment field in my db after creation is nil, and links link @upload.attachment.url just redirect to a parent object. Maybe I'm doing something wrong? I haven't used Carrierwave before.

# Model
require 'carrierwave/orm/activerecord'
class Upload < Act开发者_开发问答iveRecord::Base
  mount_uploader :attachment, AttachmentUploader
end

Went with the basics for for the attachment field

# Form
= form_for @upload, :html => { :multipart => true } do |f|
  %br
  = f.file_field :attachment

And more basics with the controller:

def create
  @upload = Upload.new(params[:upload])
  @upload.attachment = params[:file]
  if @upload.save
    redirect_to @upload
  end
end

I'm not getting any errors in my console, but the :attachment string on the student model is always nil.

Thanks!


Why u have added the line

@upload.attachment = params[:file]

remove it. it will work. attachment string is null because there is not params file in the form.

0

精彩评论

暂无评论...
验证码 换一张
取 消