Take the 2-minute tour ×

i am trying to parse a JSON structure into a database using rhonobile and my code is below;

def GetTopGainers
      :url => 'http://www.xyz.com/xyz',
      :callback => (url_for :action => :httpget_callback),
      :callback_param => "" )

    redirect :action => :viewhttp

  def httpget_callback
  $httpresult = @params['body'][0].inspect
  @params['body'].each do |dailygainers|
  mygainer = Topgainers.new
  mygainer.gainers = Topgainers["dailygainers"]["gainers"]
  mygainer.date = Topgainers["dailygainers"]["date"]
  mygainer.open = Topgainers["dailygainers"]["Open"]
  mygainer.close = Topgainers["dailygainers"]["Close"]

The problem is that nothing is bei g saved to the database.

Any ideas?

share|improve this question
add comment

3 Answers

up vote 0 down vote accepted

If your web service is not setting the proper headers, you may be getting string data back instead of json data. You would use JSON.parse(@params['body']) to convert the string to json.

Attaching the rholog.txt would help to see if this is the case.

share|improve this answer
add comment

Since dailygainers is the parameter to the do loop.You need to implement it like this

mygainer.gainers = dailygainers ["dailygainers"]["gainers"]
mygainer.date = dailygainers ["dailygainers"]["date"]
mygainer.open = dailygainers ["dailygainers"]["Open"]
mygainer.close = dailygainers ["dailygainers"]["Close"]
share|improve this answer
add comment

Try to view the log and activate the log's trace mode, clicking with right button on it and choose options->Level=Trace.
There would have some important debugging informations. If not, try to put here the complete log, so we can help you better.

share|improve this answer
add comment

Your Answer


