Note that there are some explanatory texts on larger screens.

plurals
  1. PORestKit putObject not working with Rails model
    primarykey
    data
    text
    <p>I am messing around with Restkit in iOS and rails. I cannot for the life of me figure out why my code is not working. Basically I have a ProfileModel class in iOS and I setup the object mapping for it and call the methods as below:</p> <pre><code>-(IBAction)saveButton:(id)sender { NSLog(@"Editprofile save button clicked"); RKObjectMapping *objectmappingSerialProfile = [RKObjectMapping mappingForClass:[ProfileModel class]]; [objectmappingSerialProfile mapKeyPath:@"location" toAttribute:@"country"]; [objectmappingSerialProfile mapKeyPath:@"descriptionText" toAttribute:@"description"]; [objectmappingSerialProfile mapKeyPath:@"facebookID" toAttribute:@"facebook"]; [objectmappingSerialProfile mapKeyPath:@"username" toAttribute:@"name"]; [objectmappingSerialProfile mapKeyPath:@"twitterID" toAttribute:@"twittername"]; [objectmappingSerialProfile mapKeyPath:@"website" toAttribute:@"website"]; NSDictionary *authTokenParam = [NSDictionary dictionaryWithKeysAndObjects:@"auth_token",@"pb9mp459iUj6NnmPk5C2", nil]; [[RKObjectManager sharedManager].router routeClass:[ProfileModel class] toResourcePath:[@"/modifyProfile.json" appendQueryParams:authTokenParam] forMethod:RKRequestMethodPUT]; [[RKObjectManager sharedManager].mappingProvider setSerializationMapping:objectmappingSerialProfile forClass:[ProfileModel class]]; [[RKObjectManager sharedManager] setSerializationMIMEType:RKMIMETypeJSON]; [[RKObjectManager sharedManager] putObject:self.navProfile delegate:nil]; } </code></pre> <p>When I run this code I get the following error message in the debugger window in Xcode</p> <pre><code>2012-03-20 23:51:22.815 Someprogram[3684:fe03] Editprofile save button clicked 2012-03-20 23:51:22.921 Someprogram[3684:fe03] W restkit.network:RKObjectLoader.m:241 Unable to find parser for MIME Type 'text/html' 2012-03-20 23:51:22.921 Someprogram[3684:fe03] W restkit.network:RKObjectLoader.m:262 Encountered unexpected response with status code: 500 (MIME Type: text/html) </code></pre> <p>I use rails 0.9.3 and my response in the rails window is as follows</p> <pre><code> Started PUT "/modifyProfile.json?auth_token=pb9mp459iUj6NnmPk5C2" for 127.0.0.1 at 2012-03-20 23:51:22 +0000 Processing by ProfilesController#update as JSON Parameters: {"country"=&gt;"earth2", "name"=&gt;"AdiUpdated2", "twittername"=&gt;"abc", "website"=&gt;"hmmm", "description"=&gt;"abcc", "facebook"=&gt;"abcd", "auth_token"=&gt;"pb9mp459iUj6NnmPk5C2", "profile"=&gt;{"name"=&gt;"AdiUpdated2", "description"=&gt;"abcc", "twittername"=&gt;"abc", "facebook"=&gt;"abcd", "website"=&gt;"hmmm", "country"=&gt;"earth2"}} WARNING: Can't verify CSRF token authenticity User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 9 LIMIT 1 (0.1ms) begin transaction SOLR Request (2.2ms) [ path=#&lt;RSolr::Client:0x007fc565d65f88&gt; parameters={data: &lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;add&gt;&lt;doc&gt;&lt;field name="id"&gt;User 9&lt;/field&gt;&lt;field name="type"&gt;User&lt;/field&gt;&lt;field name="type"&gt;ActiveRecord::Base&lt;/field&gt;&lt;field name="class_name"&gt;User&lt;/field&gt;&lt;/doc&gt;&lt;/add&gt;, headers: {"Content-Type"=&gt;"text/xml"}, method: post, params: {:wt=&gt;:ruby}, query: wt=ruby, path: update, uri: http://localhost:8982/solr/update?wt=ruby, open_timeout: , read_timeout: } ] (0.1ms) rollback transaction Completed 500 Internal Server Error in 22ms Errno::ECONNREFUSED (Connection refused - connect(2)): /Users/Adi/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:762:in `initialize' /Users/Adi/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:762:in `open' /Users/Adi/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:762:in `block in connect' /Users/Adi/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/timeout.rb:54:in `timeout' /Users/Adi/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/timeout.rb:99:in `timeout' /Users/Adi/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:762:in `connect' /Users/Adi/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:755:in `do_start' /Users/Adi/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:744:in `start' /Users/Adi/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:1284:in `request' rsolr (1.0.7) lib/rsolr/connection.rb:15:in `execute' sunspot_rails (1.3.0) lib/sunspot/rails/solr_instrumentation.rb:14:in `block in execute_with_as_instrumentation' activesupport (3.2.1) lib/active_support/notifications.rb:123:in `block in instrument' activesupport (3.2.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument' activesupport (3.2.1) lib/active_support/notifications.rb:123:in `instrument' sunspot_rails (1.3.0) lib/sunspot/rails/solr_instrumentation.rb:12:in `execute_with_as_instrumentation' rsolr (1.0.7) lib/rsolr/client.rb:166:in `execute' rsolr (1.0.7) lib/rsolr/client.rb:161:in `send_and_receive' (eval):2:in `post' rsolr (1.0.7) lib/rsolr/client.rb:67:in `update' rsolr (1.0.7) lib/rsolr/client.rb:87:in `add' sunspot (1.3.0) lib/sunspot/indexer.rb:101:in `add_documents' sunspot (1.3.0) lib/sunspot/indexer.rb:26:in `add' sunspot (1.3.0) lib/sunspot/session.rb:91:in `index' sunspot (1.3.0) lib/sunspot/session_proxy/abstract_session_proxy.rb:11:in `index' sunspot (1.3.0) lib/sunspot.rb:184:in `index' sunspot_rails (1.3.0) lib/sunspot/rails/searchable.rb:372:in `solr_index' sunspot_rails (1.3.0) lib/sunspot/rails/searchable.rb:470:in `perform_index_tasks' activesupport (3.2.1) lib/active_support/callbacks.rb:427:in `_run__3891665525441134440__save__2817329553089450813__callbacks' activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `__run_callback' activesupport (3.2.1) lib/active_support/callbacks.rb:385:in `_run_save_callbacks' activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks' activerecord (3.2.1) lib/active_record/callbacks.rb:264:in `create_or_update' activerecord (3.2.1) lib/active_record/persistence.rb:84:in `save' activerecord (3.2.1) lib/active_record/validations.rb:50:in `save' activerecord (3.2.1) lib/active_record/attribute_methods/dirty.rb:22:in `save' activerecord (3.2.1) lib/active_record/transactions.rb:241:in `block (2 levels) in save' activerecord (3.2.1) lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status' activerecord (3.2.1) lib/active_record/connection_adapters/abstract/database_statements.rb:190:in `transaction' activerecord (3.2.1) lib/active_record/transactions.rb:208:in `transaction' activerecord (3.2.1) lib/active_record/transactions.rb:293:in `with_transaction_returning_status' activerecord (3.2.1) lib/active_record/transactions.rb:241:in `block in save' activerecord (3.2.1) lib/active_record/transactions.rb:252:in `rollback_active_record_state!' activerecord (3.2.1) lib/active_record/transactions.rb:240:in `save' devise (2.0.4) lib/devise/models/rememberable.rb:58:in `forget_me!' devise (2.0.4) lib/devise/controllers/rememberable.rb:32:in `forget_me' devise (2.0.4) lib/devise/hooks/forgetable.rb:7:in `block in &lt;top (required)&gt;' warden (1.1.1) lib/warden/hooks.rb:14:in `call' warden (1.1.1) lib/warden/hooks.rb:14:in `block in _run_callbacks' warden (1.1.1) lib/warden/hooks.rb:9:in `each' warden (1.1.1) lib/warden/hooks.rb:9:in `_run_callbacks' warden (1.1.1) lib/warden/manager.rb:53:in `_run_callbacks' warden (1.1.1) lib/warden/proxy.rb:243:in `block in logout' warden (1.1.1) lib/warden/proxy.rb:241:in `each' warden (1.1.1) lib/warden/proxy.rb:241:in `logout' devise (2.0.4) lib/devise/controllers/helpers.rb:156:in `sign_out_all_scopes' devise (2.0.4) lib/devise/controllers/helpers.rb:261:in `handle_unverified_request' actionpack (3.2.1) lib/action_controller/metal/request_forgery_protection.rb:78:in `verify_authenticity_token' activesupport (3.2.1) lib/active_support/callbacks.rb:407:in `_run__1101336661489218557__process_action__1327857175712471554__callbacks' activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `__run_callback' activesupport (3.2.1) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks' activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks' actionpack (3.2.1) lib/abstract_controller/callbacks.rb:17:in `process_action' actionpack (3.2.1) lib/action_controller/metal/rescue.rb:29:in `process_action' actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action' activesupport (3.2.1) lib/active_support/notifications.rb:123:in `block in instrument' activesupport (3.2.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument' activesupport (3.2.1) lib/active_support/notifications.rb:123:in `instrument' actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:29:in `process_action' actionpack (3.2.1) lib/action_controller/metal/params_wrapper.rb:205:in `process_action' activerecord (3.2.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action' actionpack (3.2.1) lib/abstract_controller/base.rb:121:in `process' actionpack (3.2.1) lib/abstract_controller/rendering.rb:45:in `process' actionpack (3.2.1) lib/action_controller/metal.rb:203:in `dispatch' actionpack (3.2.1) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch' actionpack (3.2.1) lib/action_controller/metal.rb:246:in `block in action' actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:66:in `call' actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:66:in `dispatch' actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:30:in `call' journey (1.0.1) lib/journey/router.rb:68:in `block in call' journey (1.0.1) lib/journey/router.rb:56:in `each' journey (1.0.1) lib/journey/router.rb:56:in `call' actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:589:in `call' warden (1.1.1) lib/warden/manager.rb:35:in `block in call' warden (1.1.1) lib/warden/manager.rb:34:in `catch' warden (1.1.1) lib/warden/manager.rb:34:in `call' actionpack (3.2.1) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call' rack (1.4.1) lib/rack/etag.rb:23:in `call' rack (1.4.1) lib/rack/conditionalget.rb:35:in `call' actionpack (3.2.1) lib/action_dispatch/middleware/head.rb:14:in `call' actionpack (3.2.1) lib/action_dispatch/middleware/params_parser.rb:21:in `call' actionpack (3.2.1) lib/action_dispatch/middleware/flash.rb:242:in `call' rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context' rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call' actionpack (3.2.1) lib/action_dispatch/middleware/cookies.rb:338:in `call' activerecord (3.2.1) lib/active_record/query_cache.rb:64:in `call' activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:443:in `call' actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call' activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `_run__632645031902289657__call__2817329553089450813__callbacks' activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `__run_callback' activesupport (3.2.1) lib/active_support/callbacks.rb:385:in `_run_call_callbacks' activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks' actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call' actionpack (3.2.1) lib/action_dispatch/middleware/reloader.rb:65:in `call' actionpack (3.2.1) lib/action_dispatch/middleware/remote_ip.rb:31:in `call' actionpack (3.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call' actionpack (3.2.1) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call' railties (3.2.1) lib/rails/rack/logger.rb:26:in `call_app' railties (3.2.1) lib/rails/rack/logger.rb:16:in `call' actionpack (3.2.1) lib/action_dispatch/middleware/request_id.rb:22:in `call' rack (1.4.1) lib/rack/methodoverride.rb:21:in `call' rack (1.4.1) lib/rack/runtime.rb:17:in `call' activesupport (3.2.1) lib/active_support/cache/strategy/local_cache.rb:72:in `call' rack (1.4.1) lib/rack/lock.rb:15:in `call' actionpack (3.2.1) lib/action_dispatch/middleware/static.rb:53:in `call' railties (3.2.1) lib/rails/engine.rb:479:in `call' railties (3.2.1) lib/rails/application.rb:220:in `call' rack (1.4.1) lib/rack/content_length.rb:14:in `call' railties (3.2.1) lib/rails/rack/log_tailer.rb:14:in `call' rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service' /Users/Adi/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service' /Users/Adi/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run' /Users/Adi/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread' Rendered /Users/Adi/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.1/lib/action_dispatch/middleware/templates/rescues/_trace.erb (3.9ms) Rendered /Users/Adi/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.0ms) Rendered /Users/Adi/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (6.9ms) </code></pre> <p>However, if I use a program called RESTClient on mac to execute the same PUT request. It works fine and the Rails response in the window is:</p> <pre><code>Started PUT "/modifyProfile.json?auth_token=pb9mp459iUj6NnmPk5C2" for 127.0.0.1 at 2012-03-21 00:02:57 +0000 Processing by ProfilesController#update as JSON Parameters: {"country"=&gt;"earth22", "description"=&gt;"abcc", "twittername"=&gt;"abc", "facebook"=&gt;"abcd", "website"=&gt;"hmmm", "name"=&gt;"AdiUpdated2", "auth_token"=&gt;"pb9mp459iUj6NnmPk5C2", "profile"=&gt;{"name"=&gt;"AdiUpdated2", "description"=&gt;"abcc", "twittername"=&gt;"abc", "facebook"=&gt;"abcd", "website"=&gt;"hmmm", "country"=&gt;"earth22"}} WARNING: Can't verify CSRF token authenticity User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."authentication_token" = 'pb9mp459iUj6NnmPk5C2' LIMIT 1 Profile Load (0.1ms) SELECT "profiles".* FROM "profiles" WHERE "profiles"."user_id" = 9 LIMIT 1 (0.0ms) begin transaction (0.0ms) commit transaction Rendered profiles/update.json.rabl (1.9ms) Completed 200 OK in 9ms (Views: 4.4ms | ActiveRecord: 0.4ms | Solr: 0.0ms) </code></pre> <p>The only difference I am seeing is something to do with sunspot solr which is creating some sort of an issue. But the request code seems to be the same so why is Rails responding differently to this?? Can anyone please help?</p> <p>Do apologize about the long lines of code but not sure what you guys may want to look at to see what I am I doing wrong??</p> <p>Many thanks for looking</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload