Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7589441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:09:36+00:00 2026-05-30T20:09:36+00:00

I’m currently using an API and not a database, and I want to be

  • 0

I’m currently using an API and not a database, and I want to be as close as ActiveRecord, so I decided to go ahead and do exactly like this railscast here: http://railscasts.com/episodes/219-active-model

So far, my save method works well, so I can save data to the API. My problem is with the edit, my find method seems to be the problem… Here is some code!

Edit method in my controller

  def edit
    @parking = Parking.find(params[:id])
  end

Whole model

class Parking
  include ActiveModel::Validations
  include ActiveModel::Conversion
  extend  ActiveModel::Naming

  attr_accessor :name, :address, :city, :longitude, :latitude, :contributor_name, :contributor_email

  validates_presence_of :name, :address, :city, :longitude, :latitude

  def initialize(attributes = {})
    attributes.each do |name, value|
      send("#{name}=", value)
    end
  end

  def self.find(id)
    parking           = Parse.get("Parking", id.to_s) // API Call

    name              = parking["name"]
    address           = parking["address"]
    city              = parking["city"]
    longitude         = parking["location"]["longitude"]
    latitude          = parking["location"]["latitude"]
    contributor_name  = parking["contributorName"]
    contributor_email = parking["contributorEmail"]

    return self
  end

  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["name"]             = name
      parking["address"]          = address
      parking["city"]             = city
      parking["contributorName"]  = contributor_name
      parking["contributorEmail"] = contributor_email

      if (parking.save)
        return true
      end
    end
  end

  def persisted?
    false
  end
end

Here is the error I currently get:

undefined method `to_key' for Parking:Class

Extracted source (around line #1):

1: <%= form_for(@parking, :html => { :class => "form-horizontal"}) do |f| %>
2:   <% if @parking.errors.any? %>
3:     <div class="alert alert-error fade in">
4:       <a class="close" data-dismiss="alert">×</a>**

If anybody as suggestions, I’m open to any ideas really, I’m beginning with rails 🙂

Thanks!

EDIT:

When I do in my controller edit method something like:

  def edit
    @parking = Parking.new
    @parking.name              = "foo"
    @parking.address           = "foo"
    @parking.city              = "foo"
    @parking.longitude         = "foo"
    @parking.latitude          = "foo"   
  end

My view load foo in every fields no problemo, so the problem is I must be doing something wrong with the find method 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:09:37+00:00Added an answer on May 30, 2026 at 8:09 pm

    One problem is that your find method is a class method (by virtue of being ‘self.find’), meaning it does not operate on an instance of the class and therefore has no knowledge of instance variables/methods such as name, address etc.

    A better way to implement find is to instantiate a new instance of Parking, and populate it’s variables, then return it e.g.

    def self.find(id)
       raw = Parse.get("Parking", id.to_s)
    
       parking = Parking.new
       parking.name = raw["name"]
       #  etc for the others
    
       parking # Return the newly-created instance
    end
    

    This doesn’t explain the ‘undefined method’ you’re currently seeing, you may need to post up more detail to get an answer for that, particularly a full backtrace from the exception to see which bit of code is actually raising it. From the information you’ve supplied I’d guess that something within the Parse.get method is causing it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.