0

所以我使用 fb_graph gem 从 facebook 中提取数据以在我的应用程序中创建新事件。麻烦的是,我似乎无法使用 remote_image_url 来让图片通过carrierwave 上传。这是来自 organization.rb 的代码:

  page = FbGraph::Page.fetch(uri, :access_token => token)
  org_events = page.events({:fields => "name,description,picture,id,location,start_time"})
  org_events.each do |event|
    Event.create!(
        :name => event.name,
        :description => event.description,
        :location => event.location,
        :date =>event.start_time ,
        :time => event.start_time,
        :organization_id => self.id,
        :remote_image_url => event.picture  #broken code
    )
  end

这是模型顶部的已安装上传器和图像属性:

attr_accessible :image
mount_uploader :image, ImageUploader

这是我遇到的错误消息-

Can't mass-assign protected attributes: remote_image_url
4

1 回答 1

1

尝试这个,

  org_events.each do |event|
   myEvent = Event.new(
    :name => event.name,
    :description => event.description,
    :location => event.location,
    :date =>event.start_time ,
    :time => event.start_time,
    :organization_id => self.id
  )
  myEvent.remote_image_url = event.picture
  myEvent.save!
  myEvent
 end

我们正在使用 myEvent.remote_image_url ,因为 remote_image_url 是一个辅助方法

于 2014-08-08T07:11:14.140 回答