Can't assign remote_image_url carrierwave

556 views Asked by At

So I'm using the fb_graph gem to pull data from facebook to create new events within my application. Trouble is, I can't seem to use remote_image_url to get the picture to upload via carrierwave. Here's the code from 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

And here's the mounted uploader and image attribute from the top of the model:

attr_accessible :image
mount_uploader :image, ImageUploader

This is the error message I'm running into--

Can't mass-assign protected attributes: remote_image_url
1

There are 1 answers

0
Raza On

Try this,

  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

we are using myEvent.remote_image_url , because remote_image_url is a helper method