所以我正在使用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
答案 0 :(得分: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是一个辅助方法