Giter Site home page Giter Site logo

Comments (28)

adelevie avatar adelevie commented on August 11, 2024

This is not normal :)

I will investigate, and fix.

from parse-ruby-client.

allaire avatar allaire commented on August 11, 2024

I'm still a bit newby in Ruby, otherwise I would have fork it. I might try if you give me some hints haha :)

from parse-ruby-client.

adelevie avatar adelevie commented on August 11, 2024

Hints:

GeoPoint is defined in lib/parse/datatypes.rb and is tested in test/test_datatypes.rb.

Perhaps try improving the test function to show that it really should be failing, as it currently passes. Also, write an integrating test similar to the error you posted above. Right now, most tests are unit tests, and that really needs to change.

from parse-ruby-client.

allaire avatar allaire commented on August 11, 2024

I might be able to take a look at it tonight, but I think it would be wise if both of us take a look just in case haha :P

from parse-ruby-client.

lsiqueira avatar lsiqueira commented on August 11, 2024

Hi,

Just ran your code here and the object was saved correctly. What version of Ruby are you using?

from parse-ruby-client.

allaire avatar allaire commented on August 11, 2024

1.9.3

Sent from my iPhone
Envoyé de mon iPhone

On 2012-02-23, at 6:56 PM, "Leandro S."
[email protected]
wrote:

Hi,

Just ran your code here and the object was saved correctly. What version of Ruby are you using?


Reply to this email directly or view it on GitHub:
#2 (comment)

from parse-ruby-client.

adelevie avatar adelevie commented on August 11, 2024

And what version of parse-ruby-client? It should be 0.0.3.

On Thursday, February 23, 2012, Mathieu Allaire wrote:

1.9.3

Sent from my iPhone
Envoy de mon iPhone

On 2012-02-23, at 6:56 PM, "Leandro S."
<[email protected] javascript:;>
wrote:

Hi,

Just ran your code here and the object was saved correctly. What version
of Ruby are you using?


Reply to this email directly or view it on GitHub:

#2 (comment)


Reply to this email directly or view it on GitHub:
#2 (comment)

from parse-ruby-client.

lsiqueira avatar lsiqueira commented on August 11, 2024

The same I'm using. I tried with 1.9.2 and 1.8.7 and it worked too.

Here's the script I used:

require 'parse-ruby-client'

Parse.init :application_id => "<your_app_id>",
           :api_key        => "<your_api_key>"

parking_test = Parse::Object.new("ParkingTest")

data =
{
  "longitude" => 40.0,
  "latitude" => -30.0
}

point = Parse::GeoPoint.new(data)

parking_test["location"] = point

puts parking_test.to_json
parking_test.save

And the output:

{"location":{"__type":"GeoPoint","latitude":-30.0,"longitude":40.0}}

from parse-ruby-client.

allaire avatar allaire commented on August 11, 2024

Thats weird, Im using it in a rails project, but that's not a problem
I think... Weirdos, I'll try only in ruby with what you pasted

Sent from my iPhone
Envoyé de mon iPhone

On 2012-02-23, at 7:55 PM, "Leandro S."
[email protected]
wrote:

The same I'm using. I tried with 1.9.2 and 1.8.7 and it worked too.

Here's the script I used:

require 'parse-ruby-client'

Parse.init :application_id => "<your_app_id>",
          :api_key        => "<your_api_key>"

parking_test = Parse::Object.new("ParkingTest")

data =
{
 "longitude" => 40.0,
 "latitude" => -30.0
}

point = Parse::GeoPoint.new(data)

parking_test["location"] = point

puts parking_test.to_json
parking_test.save

And the output:

{"location":{"__type":"GeoPoint","latitude":-30.0,"longitude":40.0}}


Reply to this email directly or view it on GitHub:
#2 (comment)

from parse-ruby-client.

allaire avatar allaire commented on August 11, 2024

Ok, it works #1 only in Ruby, but in my Rails project, I get the same error. I don't get it

def save
  if (!valid?)
    return false
  else
  parking = Parse::Object.new("Parking")

  data =
  {
    "longitude" => 40.0,
    "latitude" => -30.0
  }

  point = Parse::GeoPoint.new(data)

  parking["location"] = point
  parking.save
end

end

and here's a screenshot of the rails error : http://d.pr/h7YA

from parse-ruby-client.

allaire avatar allaire commented on August 11, 2024

I think I've found something, I did:

Parse.init :application_id => "app_id",
           :api_key        => "api_key"

parking_test = Parse::Object.new("Parking")

data =
{
  "longitude" => 40.0,
  "latitude" => -30.0
}

point = Parse::GeoPoint.new(data)

parking_test["location"] = point

logger.debug parking_test.to_json
#parking_test.save

and in the log, it returns:

{"location":{"longitude":40.0,"latitude":-30.0}}

Normally, it should also have the

 "__type":"GeoPoint"

Correct?

from parse-ruby-client.

lsiqueira avatar lsiqueira commented on August 11, 2024

It seems to be a problem while converting the object to json. I can't see in your screenshot the correct representation for the parking object, there's nothing like "{"location":{"__type":"GeoPoint","latitude":-30.0,"longitude":40.0}}" in it.

Take a look at this SO question, it can help you: http://stackoverflow.com/questions/817287/ar-to-json-works-in-console-fails-in-browser

from parse-ruby-client.

allaire avatar allaire commented on August 11, 2024

I've tried the working code in ruby console in another controller, still failed. I also tried it in another rails project, didnt work. I don't see anything like the answer in the SO thread :(

I'm out of idea now :/

from parse-ruby-client.

lsiqueira avatar lsiqueira commented on August 11, 2024

Could you show me the gems you have installed? Do a "gem list"

I'm signing off now, but I'll try to reproduce the error using rails tomorrow :)

from parse-ruby-client.

allaire avatar allaire commented on August 11, 2024
source 'https://rubygems.org'

gem 'rails', '3.2.1'

gem 'pg'
gem 'parse-ruby-client'
gem 'bootstrap-sass', :git => 'git://github.com/thomas-mcdonald/bootstrap-sass.git'

group :production do
  gem 'unicorn'
  gem 'newrelic_rpm'
end

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer'

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

Thanks alot!

from parse-ruby-client.

allaire avatar allaire commented on August 11, 2024

I think it might be a as_json to_json issue, but not sure... See:

http://jonathanjulian.com/2010/04/rails-to_json-or-as_json/
http://stackoverflow.com/a/3630186
http://stackoverflow.com/questions/2556468/override-as-json-or-to-json-model-class-name

from parse-ruby-client.

lsiqueira avatar lsiqueira commented on August 11, 2024

Yes, you were right. Just added as_json method to all classes and the gem is working fine in a rails project.

from parse-ruby-client.

allaire avatar allaire commented on August 11, 2024

Is this a 'bug' ? Is it the responsibility of the gem to use as_json
or we should overwrite something in the project? Perhaps could you
share what you modified?

Thank you!

Sent from my iPhone
Envoyé de mon iPhone

On 2012-02-25, at 1:30 AM, "Leandro S."
[email protected]
wrote:

Yes, you were right. Just added as_json method to all classes and the gem is working fine in a rails project.


Reply to this email directly or view it on GitHub:
#2 (comment)

from parse-ruby-client.

lsiqueira avatar lsiqueira commented on August 11, 2024

Here's what I modified:
lsiqueira@bb4135f

from parse-ruby-client.

allaire avatar allaire commented on August 11, 2024

Awesome! Nice work @lsiqueira !

Would you mind explaining a bit more in details what was the problem in this particular situation?

Also, I see you changed the previous method to as_json but kept a to_json method, that's simply to not break previous compatibility? Or we have to use as_json with rails and to_json for everything else?

Thank you!

from parse-ruby-client.

adelevie avatar adelevie commented on August 11, 2024

@allaire, did this fix work for you?

In a perfect world, I'd like to have a test case that includes a Rails environment. However, if this did fix the issue, I'm inclined to just close it and not worry about it.

from parse-ruby-client.

lsiqueira avatar lsiqueira commented on August 11, 2024

@allaire

When using the gem inside a Rails project the to_json method inside datatypes.rb was not being called, the as_json method was the one being used. I read this answer before realizing that: http://stackoverflow.com/a/6880638/106637

@adelevie

I don't know how to create a test case that includes a Rails environment, do you? If not, this is something we should add to the project's todo list :)

from parse-ruby-client.

allaire avatar allaire commented on August 11, 2024

Patch is fixing the issue, clever work @lsiqueira and thanks for the explanation!

from parse-ruby-client.

allaire avatar allaire commented on August 11, 2024

Also, may I ask what's the best way to test a patch like that? Is it by modyfing the gem directly (in my case on Mac in the .rvm folder) ?

from parse-ruby-client.

adelevie avatar adelevie commented on August 11, 2024

Nope, that would be a bad way to do it, imo.

Clone the repo somewhere. Run rake test as needed. To use your local gem in another app, point to it in that app's Gemfile:

gem "restivus", :path => "../path/to/local/gem"

Then google around for GitHub's procedure on pull requests if you made something you think should be in the main repo.

from parse-ruby-client.

allaire avatar allaire commented on August 11, 2024

That make sense, thank you.

By the way, you can accept that pull request, it works flawlessly for my issue. So I'll close this, thank you.

from parse-ruby-client.

adelevie avatar adelevie commented on August 11, 2024

I did merge the request.

from parse-ruby-client.

lsiqueira avatar lsiqueira commented on August 11, 2024

Thank you guys!

from parse-ruby-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.