On Mon, Jul 13, 2009 at 3:31 AM, Reinier Balt<[email protected]> wrote:
>>
>> (2) if I'm correct, and I can't get to that header, then when I create
>> a new action with a POST to todos.xml from jquery.ajax, I can't
>> actually take someone to the action they've just created, or otherwise
>> programatically access it/modify it/etc., since that information is in
>> the location header rather than in the data. As I understand best
>> practices for POST[1], it would be good to return the URI (or perhaps
>> even simpler just the action's ID number?) in the response, not just
>> in the header. I'd be much obliged for my little project if someone
>> would help that happen in git, or at least point me at the right place
>> to make it happen.
>>
>
> Don't know enough about jquery wrt getting to the header. To put the new
> url in the body is not that difficult I think. For example in the
> project_controller, I think you can add :text => project_url(@project) to
> line 95 to add the url to the body of the response. But I have not tried
> it...
>
> http://github.com/bsag/tracks/blob/2497ea9fea1a7528adb2b41f450f6dfb78a47a8c/
> app/controllers/projects_controller.rb#L95

That is the right place. I think the following change to that file is
probably better; it gives the project ID, which can be trivially used
to build the URL but can also easily be used for other things .
(Presumably if you're calling the API you already know the base URL to
use.)

-          head :created, :location => project_url(@project)
+          head :created, :location => project_url(@project), :text =>
@project.id

I've applied this change locally and it works fine, and I can't
imagine it breaking any existing consumers of the API, so I think it
can be applied to trunk. (I can attach a real patch if you really
want... I admit I don't expect yet to do enough hacking to actually
merit getting a real github account, but I can do that if you really
want me to too :)

Luis
_______________________________________________
Tracks-discuss mailing list
[email protected]
http://lists.rousette.org.uk/mailman/listinfo/tracks-discuss

Reply via email to