undefined method `[]' for nil:NilClass

Archived from the Transloadit support forum. Originally posted on September 10, 2012; details may be outdated, see our docs for current behavior. Original thread

Having some issues with the ruby gem:

NoMethodError:

   undefined method `[]' for nil:NilClass
 # ./lib/image_helper.rb:51:in `save_image'

The code in the helper looks like this:

def save_image(user_id)

transloadit = Transloadit.new(
  :key    => 'xxx',
  :secret => 'xxx'
)

transloadit.assembly(
  :template_id => "xxx",
  :fields => {
    importUrl: "http://graph.facebook.com/#{user_id}/picture?type=large",
    exportUrl: "users2/#{user_id}.jpg"
  }
).submit!

It’s the submit! that makes the exception happen. If I add open(‘…’) after the submit!, it works fine. But since I’m using the http/import robot in the template, I dont have a file to pass in the open method.

Hi there,

I’m one of the maintainers of the ruby-sdk and rails-sdk, so I hope I can help.

You’re missing a step there, that’s why it fails. Try it like this:

` import = transloadit.step(
‘:original’, ‘/http/import’, url: “http://graph.facebook.com/#{user_id}/picture?type=large” )

transloadit.assembly(
steps: [import], template_id: “xxx”, fields: {exportUrl: “users2/#{user_id}.jpg”} ).submit! `

That will work.

Let me know if you still have a question

Somehow the formatting fucked up, so please ignore the backticks in the previous example.

Alright closing this ticket for now.

Please re-open the ticket as you see fit, guys.

Closing for real now.