java - how to pass multiple entity of array HTTP post from Android to Rails 4 -
the rails app has nested forms, working in web , correctly save.but have problem in android part, values not saving.
here's code in rails:
<%= nested_form_for @patient |f| %> <div class="title"> general details </div> <div class="name"> <%= f.text_field :firstname, placeholder: 'first name' %> <%= f.text_field :middlename, placeholder: 'middle name' %> <%= f.text_field :lastname, placeholder: 'last name' %> </div> <div> <%= f.label "immunization" %> <%= f.fields_for :ph_immunizations |ph| %> <%= render "ph_immunization_fields", :f => ph %> <% end %> <p><%= link_to_add_fields "+ add", f, :ph_immunizations %></p> </div> <% end %>
the partial:
<p> <%= f.hidden_field :patient_id, value: @patient.id %> <%= f.collection_select(:immunization_id,immunization.order(:description),:id,:description, {include_blank: '', selected: field_value(:immunization_id) }, class: "js-immunization js-select2", id: "immunization-select", "data-placeholder" => "immunization") %> <%= f.link_to_remove "remove" %> </p>
android:
httpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost("https://xxxxx/patients"); list<namevaluepair> immunizatiovaluepairs = new arraylist(); immunizatiovaluepairs.add(new basicnamevaluepair("ph_immunizations_attributes[1234567890123[immunization_id]]", integer.tostring(1))); immunizatiovaluepairs.add(new basicnamevaluepair("ph_immunizations_attributes[1234567890124[immunization_id]]", integer.tostring(2))); immunizatiovaluepairs.add(new basicnamevaluepair("ph_immunizations_attributes[1234567890123[patient_id]]", integer.tostring(98))); immunizatiovaluepairs.add(new basicnamevaluepair("ph_immunizations_attributes[1234567890124[patient_id]]", integer.tostring(98))); httppost.setentity(new urlencodedformentity(immunizatiovaluepairs)); httpresponse response = httpclient.execute(httppost); inputstream responsecontent = response.getentity().getcontent();
android's logs in server:
{"ph_immunizations_attributes"=>{"1234567890123"=>{"immunization_id"=>"1", "patient_id"=>"98"}, "1234567890124"=>{"immunization_id"=>"2", "patient_id"=>"98"}}}
java android ruby-on-rails ruby ruby-on-rails-4
No comments:
Post a Comment