Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the most appropriate way to create an object in Ruby on Rails app through an http POST?
    text
    copied!<p>I'm fairly new to web development in general and I've been working on a Ruby on Rails app that I want (eventually) to interact with an Android app. I currently am looking for the most appropriate and safe way to create an object from an http POST that would be sent from the Android app.</p> <p>The way I'm approaching it to initially achieve this by using a REST client extension for chrome trying to send POSTs to my app on localhost and have it create an object from the POST information.</p> <p>This is the result of the POST from the chrome extension:</p> <pre><code>Started POST "/problems" for 127.0.0.1 at 2012-09-15 14:16:19 -0400 Processing by ProblemsController#create as */* Parameters: {"user"=&gt;"7876483097", "latitude"=&gt;"18.378383", "longitude"=&gt;"-67.026201", "ptype"=&gt;"2", "description"=&gt;"Poste roto"} ←\[1m←\[36m (0.0ms)←\[0m ←\[1mbegin transaction←\[0m ←\[1m←\[35m (0.0ms)←\[0m rollback transaction Rendered problems/new.html.erb within layouts/application (31.0ms) Rendered layouts/_shim.html.erb (0.0ms) ←\[1m←\[36mUser Load (0.0ms)←\[0m ←\[1mSELECT "users".* FROM "users" WHERE "users"."remember_token" = 'gdmKIurcqDOMoDGWE4IBng' LIMIT 1←\[0m Rendered layouts/_header.html.erb (4.0ms) Rendered layouts/_footer.html.erb (1.0ms) Completed 200 OK in 93ms (Views: 87.0ms | ActiveRecord: 0.0ms) </code></pre> <p>Right where "rollback transaction" appears means that @problem.save in the create method has failed. Can anybody help identify what I'm missing or how i should change my approach to do it correctly.</p> <p>Here is my model schema:</p> <pre><code> create_table "problems", :force =&gt; true do |t| t.string "user" t.float "latitude" t.float "longitude" t.integer "ptype" t.string "description" t.integer "priority" t.integer "status" t.datetime "created_at", :null =&gt; false t.datetime "updated_at", :null =&gt; false t.string "avatar_file_name" t.string "avatar_content_type" t.integer "avatar_file_size" t.datetime "avatar_updated_at" t.boolean "gmaps" t.string "address" end </code></pre> <p>Here is my create method:</p> <pre><code> def create @problem = Problem.new(params[:problem]) if @problem.save flash[:success] = "Problema guardado" redirect_to @problem else @problem.errors.full_messages flash.now[:error] = 'Informacion incorrecta' render 'new' end end </code></pre> <p>This is the POST body:</p> <pre><code>user=7876483097&amp;latitude=18.378383&amp;longitude=-67.026201&amp;ptype=2&amp;description=Poste+roto </code></pre> <p>And, this is the problem model and validations</p> <pre><code>class Problem &lt; ActiveRecord::Base acts_as_gmappable :latitude =&gt; 'latitude', :longitude =&gt; 'longitude', :process_geocoding =&gt; :geocode?, :address =&gt; "address", :normalized_address =&gt; "address", :msg =&gt; "Lo sentimos, ni Google puede localizar esa direccion" attr_accessible :user, :latitude, :longitude, :ptype, :description, :avatar, :address validates(:user, presence: true) validates(:latitude, presence: true) validates(:longitude, presence: true) validates(:ptype, presence: true) </code></pre> <p>Thanks in advance.</p>
 

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