Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Receive POST from External Form

I have a form on another website (using a different backend) that I want to be able to POST to my Rails application (on a different domain).

  • How do I generate a valid authenticity token for the external form so that my Rails app will accept it?
  • Assuming I can do the answer to the above question--is there anything else special I need to do to make this work? Apart from the authenticity token, the rest of it seems pretty straightforward to me...

Thanks for the help!

like image 874
neezer Avatar asked Nov 13 '09 16:11

neezer


2 Answers

You can't generate an autenticity token from outside your Rails app. What you can do, is to disable the token protection only for this action and use a custom implementation based on a before_filter.

skip_before_filter :verify_authenticity_token, :only => :my_action
before_filter :verify_custom_authenticity_token, :only => :my_action

def verify_custom_authenticity_token
  # checks whether the request comes from a trusted source
end
like image 91
Simone Carletti Avatar answered Oct 06 '22 01:10

Simone Carletti


You could just remove the check by adding a filter like:

skip_before_filter :verify_authenticity_token, :only => :action_name
like image 36
JRL Avatar answered Oct 06 '22 00:10

JRL