To solve this problem, the Rails Apps
need to let each other access or let's say ping each other. In order to do that, we have to use something like CORS, to allow AJAX Request from Other Domain.
Here is a simpler way that I used to go allow method accesses article, it might sound confusing at first.
To do perform this on both sides, you need to create an actual complete app for the Faye
as well, unlike what is given on the Faye chat server Repo I've attached in my question.
In the Actual/Main App include this in your application_controller.rb
before_filter :cors_preflight_check
after_filter :cors_set_access_control_headers
#For all responses in this controller, return the CORS access control headers.
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = 'http://YOURFAYEAPP.com'
headers['Access-Control-Allow-Methods'] = 'POST, PUT, DELETE, GET, OPTIONS'
headers['Access-Control-Request-Method'] = 'http://YOURFAYEAPP.com'
headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization'
end
# If this is a preflight OPTIONS request, then short-circuit the
# request, return only the necessary headers and return an empty
# text/plain.
def cors_preflight_check
if request.method == :options
headers['Access-Control-Allow-Origin'] = 'http://YOURFAYEAPP.com'
headers['Access-Control-Allow-Methods'] = 'POST, PUT, DELETE, GET, OPTIONS'
headers['Access-Control-Request-Method'] = 'http://YOURFAYEAPP.com'
headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization'
render :text => '', :content_type => 'text/plain'
end
end
In that way, both can send and receive requests.
Don't put *
instead of the request parameter
, it's a security issue. You can cut down the methods
to only Get
and Post
.