Skip to content

Instantly share code, notes, and snippets.

View shyam-habarakada's full-sized avatar
🌱
In the weeds

Shyam Habarakada shyam-habarakada

🌱
In the weeds
  • Smartsheet, 10Kft
  • Seattle, WA
  • X @shyamh
View GitHub Profile
@shyam-habarakada
shyam-habarakada / rails-3.2-issue--Gemfile.rb
Created January 23, 2012 22:13
rails-3.2-issue--Gemfile
source 'http://rubygems.org'
gem 'rails', '3.2.0'
gem 'rake', '0.9.2.2'
gem 'mysql2', '0.2.6'
# Gems used only for assets and not required in production by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
@shyam-habarakada
shyam-habarakada / rails-3.2-errors.md
Created January 23, 2012 20:51
rails 3.2 errors

Getting the error undefined method `accept' for nil:NilClass in my controller. This is on the development environment running on OSX with mysql. Below is the full stack trace and also my bundle/gem setup information.

$ ruby --version
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.0.0]

RAILS FRAMEWORK TRACE

@shyam-habarakada
shyam-habarakada / rails-model-before-save-fixtures.rb
Created November 13, 2011 17:23
rails models with before_save callbacks and fixtures
# == Schema Information
#
# Table name: users
#
# id :integer(4) not null, primary key
# first_name :string(255)
# last_name :string(255)
# email :string(255)
# thumbnail :string(255)
# user_type_id :integer(4)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">
<head>
<title>LDVC Seadragon Prototype</title>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=no;">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<style type="text/css">
// Encounter is a managed object, and has a dynamic property called patient. of kind Patient.
// Patient is a managed object as well, and has a dynamic property id.
[objectManager.router routeClass:[Encounter class]
toResourcePath:@"/patients/:patient.id/encounters"
forMethod:RKRequestMethodPOST];
// Routing isn't resolving as expected.
@shyam-habarakada
shyam-habarakada / rest-kit-mapping-options.js
Created September 13, 2011 23:02
rest-kit-mapping-options
/*
* RestKit QUESTION
*
* What is the correct way to map the following server response variants, and
* is there a preferred option?
*
* Also, keeping in mind that these responses can represent nested objects that need to
* be mapped to corresponding object hierarchies on the client side. I can give more
* examples of that if needed.
*
@shyam-habarakada
shyam-habarakada / date-time-encoding-error-with-rabl
Created September 12, 2011 19:03
date-time-encoding-error-with-rabl
OkJson::Error in Posts#index
Showing /Users/shyam/dev/apx-server/app/views/posts/index.rabl where line #1 raised:
cannot encode ActiveSupport::TimeWithZone: Fri, 09 Sep 2011 21:47:05 UTC +00:00
Extracted source (around line #1):
1: collection @posts
2:
3: extends "posts/show"
@shyam-habarakada
shyam-habarakada / restkit-mappings.md
Created September 2, 2011 20:05
mapping options

Response format A:

[
  {"id_str":"1","id":1,"last_name":"Johnson","date_of_birth":null,"display_name":"Stephanie Johnson","first_name":"Stephanie"},
  {"id_str":"2","id":2,"last_name":"Black","date_of_birth":null,"display_name":"Joe Black","first_name":"Joe"}
]

Response format B:

$ curl -i -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"first_name":"Jenny","last_name":"McCarthy"}' http://127.0.0.1:3000/patients
HTTP/1.1 200 OK
X-Ua-Compatible: IE=Edge
Etag: "6295adeacd1c3439689e6be85996ddf5"
Connection: Keep-Alive
Content-Type: application/json; charset=utf-8
Date: Thu, 01 Sep 2011 20:23:06 GMT
Server: WEBrick/1.3.1 (Ruby/1.8.7/2010-01-10)
X-Runtime: 0.057011
Content-Length: 120

This is a title

Recently I went through the process of using RestKit and core data to implement the data stack for a new iOS application. The application needed to communicate with a JSON REST server (implemented with RoR) and cache the data obtained for faster and offline access. The app reads data from the server as well as POSTs new data to the server and makes updates to existing data.

The process of getting this to work was interesting, and not without dead-ends. I got things working in the end, and happy with the decision to go with RestKit. I filed a few bugs against RestKit along the way :-)

Below are some note that would help others who go down this path. The hope is that these tips would help avoid some of the dead-ends I hit and callout gotcha's in working with RestKit and core-data.

This is the first level of quoting.