载波-Rails 3.1-未定义的方法:image_will_change [英] carrierwave - rails 3.1- undefined method: image_will_change

查看:103
本文介绍了载波-Rails 3.1-未定义的方法:image_will_change的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到如下错误:

undefined method `post_image_will_change!' for #<Post:0xf4e9184>
app/controllers/posts_controller.rb:43:in `new'
app/controllers/posts_controller.rb:43:in `create'

我已将其包含在发布"模型中:

I've included this in my "post" model:

 attr_accessible :title, :name, :content, :post_image
 mount_uploader :post_image, PostImageUploader

,在_form.html.erb中,我添加了:

and in _form.html.erb I've added:

 :html =>  { :multipart => true }

我查看了 CarrierWave错误,但这对我没有帮助.

I looked CarrierWave Error but that doesn't help me.

有关产生该错误的任何线索?我已经迁移了数据库,依此类推(准确地遵循了载波上的railscasts指南.)

Any clues of what generates that error? I've migrated the database and so forth (followed the railscasts guide on carrierwave exactly..)

推荐答案

他修正了OP的评论,但是没有答案,所以我想我会为将来遇到此问题的人添加一个,包括我自己直到我发现了:)

The OP comments that he fixed it, however there's no answer set so I thought I'd add one for people coming across this in the future, which included myself until I figured it out :)

未定义的方法"x_will_change!"如果您忘记在模型的db表中添加列,则会发生#.如果您有模型用户和AvatarUploader,并且已按照Carrierwave文档中的说明安装了上传器:

undefined method `x_will_change!' for # happens if you forget to add a column in your model's db table. If you have a model User and a AvatarUploader, with the uploader mounted as in the Carrierwave docs:

class User < ActiveRecord::Base
  mount_uploader :avatar, AvatarUploader
end

然后错误将显示为

undefined method `avatar_will_change!' for #<User:0x00...>

要解决此问题(基于此示例),请在控制台中添加以下内容:

To fix it (based on this example) add a column in a migration run the following in the console:

rails g migration AddAvatarToUsers avatar:string

这将产生以下迁移:

class AddAvatarToUsers < ActiveRecord::Migration
  def change
    add_column :users, :avatar, :string
  end
end

然后迁移以应用更改(再次在控制台中):

Then migrate to apply the change (again in the console):

rake db:migrate

这篇关于载波-Rails 3.1-未定义的方法:image_will_change的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆