小编bax*_*ang的帖子

Carrierwave文件名在update_attributes上不断变化

我有模型公司和公司已经安装了carrierwave uploader Logo.

class Company < ActiveRecord::Base
  mount_uploader :logo, LogoUploader
Run Code Online (Sandbox Code Playgroud)

图片上传工作,但我有update_attributes的问题.当用户想要仅更新公司的描述或标题,而不是上传新图像时 - DB中的文件名值每次都在更改.这是一个简单的例子:

1.9.3-p545 :004 > a = Company.last
1.9.3-p545 :005 > a.update_attributes(:title => "test title 2")
 (0.4ms)  BEGIN
  Company Exists (0.9ms)  SELECT 1 AS one FROM `companies` WHERE (`companies`.`title` = BINARY 'test title 2' AND `companies`.`id` != 37) LIMIT 1
  Company Load (0.7ms)  SELECT `companies`.* FROM `companies` WHERE `companies`.`id` = 37 LIMIT 1
   (0.7ms)  UPDATE `companies` SET `title` = 'test title 2', `logo` = '1396206630_1f288be4.jpg', `updated_at` = '2014-03-30 19:10:30' …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails update-attributes ruby-on-rails-3 carrierwave

6
推荐指数
1
解决办法
1280
查看次数

模型中包含的辅助方法为"错误"生成"未定义的局部变量或方法`config'

我有一个非常复杂的辅助方法,也需要在模型中.我只是在我的模型中包含一些帮助程序,但是同样的方法不适用于Rails 3.0.7.

module ContentsHelper
  def content_teaser record
    # it uses image_tag, truncate, raw, and some others.
  end
end

class Content < ActiveRecord::Base
  include ActionView::Helpers::TagHelper
  include ActionView::Helpers::UrlHelper
  include ActionController::UrlFor
  include ActionView::Helpers::TextHelper
  include ActionView::Helpers::RawOutputHelper
  include ActionView::Helpers::AssetTagHelper
  include ContentsHelper
  include Rails.application.routes.url_helpers

  def teaser
    content_teaser self.body        
  end
end
Run Code Online (Sandbox Code Playgroud)

和我有的错误信息

undefined local variable or method `config' for #<Content:0x10bac7248>
app/helpers/contents_helper.rb:8:in `content_teaser'
app/models/content.rb:70:in `teaser'
Run Code Online (Sandbox Code Playgroud)

任何建议/意见?

ruby-on-rails-3

2
推荐指数
1
解决办法
3390
查看次数