views:

59

answers:

2

I'd like to set up my Rails controller to only perform a create action if the request has a JavaScript or xml payload. I don't want HTML form submits to trigger a create. Ideally, attempting to do so would send you to an page explaining that you can't do that.

I think one solution would be to put a prepend_before_filter on the controller that would check the content_type and accept headers of the request.

But is there a cleaner or more common way to achieve this?

A: 

I think one solution would be to put a prepend_before_filter on the controller that would check the content_type and accept headers of the request.

I think you've got the right idea here.

Kyle W. Cartmell
A: 

My way would be to put your function in the model by using the before_create method