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

  • Home
  • SEARCH
  • 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 7601777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:14:46+00:00 2026-05-30T23:14:46+00:00

I’ve got a relatively simple Rails app that takes a form with nested params

  • 0

I’ve got a relatively simple Rails app that takes a form with nested params that includes a photograph. It looks like this:

class List < ActiveRecord::Base
  has_many :list_items
  has_many :people, through: list_items
end

class ListItem < ActiveRecord::Base
  belongs_to :list
  belongs_to :person, autosave: true

  has_attached_file :picture,
    :storage => :s3,
    :bucket => 'myfreebielist',
    :s3_credentials => {
      :access_key_id => ENV['S3_KEY'],
      :secret_access_key => ENV['S3_SECRET']
    }


  def autosave_associated_records_for_person
    if new_person = Person.find_by_name(Person.name) then
      self.person = new_person
    else
      self.person.save!
    end
  end
end

class Person < ActiveRecord::Base
  has_many :list_items
end

I set up a test new form, just to make sure everything works, and it does, nice and pretty:

<%= form_for @list do |f| %>
  List name: <%= f.text_field :name %><br/>
  <%= f.fields_for :list_items do |lif| %>
    <%= lif.fields_for :person do |pif| %>
    Person name: <%= pif.text_field :name %>
    <% end %>
    Picture: <%= lif.file_field :picture %>
    <br/>
  <% end %>
  <%= f.submit %>
<% end %>

OK, so I want to be able to post a new list, with list items (and their related picture images), as well as the person for that list item. I have this code that I’m testing with in Objective C:

NSMutableDictionary *listParams = [NSMutableDictionary dictionary];
[listParams setValue:@"Test One" forKey:@"name"];

NSMutableDictionary *listItems = [NSMutableDictionary dictionary];

// Generate each list item -- a person and a photo.
NSDictionary *person1 = [NSDictionary dictionaryWithKeysAndObjects:@"name", @"John Smith", nil];
NSDictionary *listItem1 = [NSDictionary dictionaryWithKeysAndObjects:@"person_attributes", person1, nil];
[listItems setValue:listItem1 forKey:@"0"];
[listParams setValue:listItems forKey:@"list_items_attributes"];

NSMutableDictionary *params = [NSMutableDictionary dictionary];
[params setValue:listParams forKey:@"list"];

[[RKClient sharedClient] post:@"/lists" params:params delegate:self];

This also works fine, with the notable absence of the picture.

Now, I understand that using an RKParams instead of an NSDictionary is how you’re supposed to handle this type of request, but when I post using an RKParams there is all manner of strange things arriving at the rails side — lots of \n newlines, spaces and things around the keys. I tried using an RKParams with an attachment as part of person1, but it seems to just send the string representation of the name of the object RKParams object.

I feel like I’m so, so close but I’ve been hitting my head against this for hours now. Any help would be appreciated.

Environment: Xcode 4.3, Rails 3.2.1.

  • 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-30T23:14:48+00:00Added an answer on May 30, 2026 at 11:14 pm

    The answer is: JSON. I had to adjust the server to support JSON, something I should have done at the outset. That’s what all the spaces and \ns are about. Note to self: don’t program an all-nighter, no matter how motivated you are.

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words
I have just tried to save a simple *.rtf file with some websites and
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 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.