title: Rails: Error occurred while parsing request parameters. (HTTP PUT)
body: <p>I created one simple Rails app:</p>
  
  <pre><code>$ rails new server --database=postgresql
  $ rails generate scaffold contact name address city zip phone
  $ git init
  $ git add .
  $ git commit -m "initial"
  $ rake db:create
  $ rake db:migrate
  </code></pre>
  
  <p>Then I created an iOS client using AFNetworking framework. And I added new records to the database that way:</p>
  
  <pre><code>+ (void) add: (Contact *)contact block:(void (^)(NSError *error))block{
      NSDictionary *fields = @{@"name": contact.name,
                               @"address": contact.address,
                               @"city": contact.city,
                               @"zip": contact.zip,
                               @"phone": contact.phone
                               };
  
      NSDictionary *params = @{@"contact":fields,
                               @"commit":@"add Contact"};
  
      NSString *urlString = @"http://0.0.0.0:300/contacts/";
  
      AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
  
      manager.requestSerializer = [AFJSONRequestSerializer serializer];
      [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
      [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
  
      [manager POST:urlString parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
          //.......
      } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
          //......
      }];
  
  }
  </code></pre>
  
  <p>And then I listed the records that way:</p>
  
  <pre><code>+ (void)list:(void (^)(NSArray *contacts, NSError *error))block{
      AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
  
      manager.requestSerializer = [AFJSONRequestSerializer serializer];
      [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
      [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
  
      NSString *url = @"http://0.0.0.0:300/contacts/";
      [manager GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
          NSMutableArray *mutableContacts = [NSMutableArray arrayWithCapacity:[responseObject count]];
          for(NSDictionary *item in responseObject) {
              Contact *contact = [[Contact alloc] initWithAttributes:item];
              [mutableContacts addObject:contact];
          }
  
      } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
          // .... 
      }];
  }
  </code></pre>
  
  <p>And when I tried to update records using this code: </p>
  
  <pre><code>+ (void) update: (Contact *)contact block:(void (^)(NSError *error))block{
      NSDictionary *fields = @{@"name": contact.name,
                               @"address": contact.address,
                               @"city": contact.city,
                               @"zip": contact.zip,
                               @"phone": contact.phone
                               };
  
      NSDictionary *params = @{@"contact":fields,
                               @"commit":@"Update Contact"};
  
  
      // url example ==&gt;&gt; http://0.0.0.0:3000/contact/2.json
      NSString *urlString = contact.url;
  
      AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
  
      manager.requestSerializer = [AFHTTPRequestSerializer serializer];
      [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
      [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
  
      [manager PUT:urlString parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
          if (block) {
              block(nil);
          }
          NSLog(@"JSON: %@", responseObject);
      } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
          NSLog(@"Response:  %@", [operation description]) ;
          if (block) {
              block(error);
          }
          NSLog(@"Error: %@", error);
      }];
  }
  </code></pre>
  
  <p>I received this error:</p>
  
  <pre><code>Started PUT "/contacts/2.json" for 192.168.0.3 at 2015-02-03 16:16:05 -0200
  Error occurred while parsing request parameters.
  Contents:
  
  commit=Update%20Contact&amp;contact[address]=xxxxxxx&amp;contact[city]=xxxxxxx&amp;contact[name]=BLA%20BLA%20BLA&amp;contact[phone]=xxxxxxx&amp;contact[zip]=xxxxxxx
  
  ActionDispatch::ParamsParser::ParseError (795: unexpected token at 'commit=Update%20Contact&amp;contact[address]=xxxxxxx&amp;contact[city]=xxxxxxx&amp;contact[name]=BLA%20BLA%20BLA&amp;contact[phone]=xxxxxxx&amp;contact[zip]=xxxxxxx'):
    actionpack (4.1.7) lib/action_dispatch/middleware/params_parser.rb:53:in `rescue in parse_formatted_parameters'
    actionpack (4.1.7) lib/action_dispatch/middleware/params_parser.rb:32:in `parse_formatted_parameters'
    actionpack (4.1.7) lib/action_dispatch/middleware/params_parser.rb:23:in `call'
    actionpack (4.1.7) lib/action_dispatch/middleware/flash.rb:254:in `call'
    rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
    rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
    actionpack (4.1.7) lib/action_dispatch/middleware/cookies.rb:560:in `call'
    activerecord (4.1.7) lib/active_record/query_cache.rb:36:in `call'
    activerecord (4.1.7) lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
    activerecord (4.1.7) lib/active_record/migration.rb:380:in `call'
    actionpack (4.1.7) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
    activesupport (4.1.7) lib/active_support/callbacks.rb:82:in `run_callbacks'
    actionpack (4.1.7) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
    actionpack (4.1.7) lib/action_dispatch/middleware/reloader.rb:73:in `call'
    actionpack (4.1.7) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
    actionpack (4.1.7) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
    actionpack (4.1.7) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
    railties (4.1.7) lib/rails/rack/logger.rb:38:in `call_app'
    railties (4.1.7) lib/rails/rack/logger.rb:20:in `block in call'
    activesupport (4.1.7) lib/active_support/tagged_logging.rb:68:in `block in tagged'
    activesupport (4.1.7) lib/active_support/tagged_logging.rb:26:in `tagged'
    activesupport (4.1.7) lib/active_support/tagged_logging.rb:68:in `tagged'
    railties (4.1.7) lib/rails/rack/logger.rb:20:in `call'
    actionpack (4.1.7) lib/action_dispatch/middleware/request_id.rb:21:in `call'
    rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
    rack (1.5.2) lib/rack/runtime.rb:17:in `call'
    activesupport (4.1.7) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
    rack (1.5.2) lib/rack/lock.rb:17:in `call'
    actionpack (4.1.7) lib/action_dispatch/middleware/static.rb:84:in `call'
    rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
    railties (4.1.7) lib/rails/engine.rb:514:in `call'
    railties (4.1.7) lib/rails/application.rb:144:in `call'
    rack (1.5.2) lib/rack/lock.rb:17:in `call'
    rack (1.5.2) lib/rack/content_length.rb:14:in `call'
    rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
    /Users/gazollajunior/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
    /Users/gazollajunior/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
    /Users/gazollajunior/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
  </code></pre>
  
  <p>I followed the same pattern from List and add methods and the update does not work.</p>
  
  <p>What am I doing wrong ?</p>