Updating an attribute from a POST request

Hi all,

I’d like to update an attribute in a model via an external POST request.
The external request is coming from an iOS iPhone application but I
imagine this is not relevant.

If I have a model App and it has the following attributes…

App
apple_identifier :integer
popularity :integer

I imagine I need an update reference in routes.rb like this…

map.resources :apps, :only => [:index, :show, :update]

I then have the following in routes

 PUT /apps/:id(.:format) {:action=>"update", :controller=>"apps"}

So what might the apps_controller update action look like to receive the
request and update the popularity count by one…I pretty much think I
can solve that myself really I just want to know my thinking it on the
right lines.

One thing, rake routes says PUT - is that the same as post?

What would the URL look like that I ask my iOS dev for, is it as simple
as what follows - any gotchas?

I imagine…(POST to…) http://server.com/apps/456

def update
find App record 456 and update it’s popularity count
end

Is it really that simple ?

Update to this…

Transpires that we’d like to use the apple_identifier in the URL to do
the update rather than the more standard rails db App.id.

So the URL submitted to do the update could look more like this.

POST to
http://server.com/apps?apple_identifier=6383940&incremental_update=1

Where the 6383940 is the apple_identifier I wish to update (passed as a
parameter and found in the update action).

Is this likely to work out?

Bb

Also, slight aside but can I simulate the action of the iOS app
submitting the URL with a curl command on my mac or similar. For
testing.

On Jan 9, 8:49am, bingo bob [email protected] wrote:

So what might the apps_controller update action look like to receive the
request and update the popularity count by one…I pretty much think I
can solve that myself really I just want to know my thinking it on the
right lines.

One thing, rake routes says PUT - is that the same as post?

Nope. PUT and POST are two different methods

sounds about right.

Fred