how to call method in one application from another application in ruby on rails -


i want call method , response in application application in ruby on rails technology, here cross site scripting problem there. so, can resolve issue please me great.

http://video_tok.com/courses/get_course

def get_course   @course = course.find(params[:id]) end 

now want call above method application running in edupdu.com domain

http://edupdu.com/call_course_method

def call_course_method   @course = redirect_to "http://video_tak.com/courses/get_course/1" end 

but redirect video_tak.com application. want call get_course method , @course object internally without redirect site.

thanks in advance.

cross-domain ajax indeed problem, none not solved. in get_course method return course objects json response so:

render json: @course 

from there on either retrieve course through javascript (ajax), here should use jsonp or inside rails issuing http request.

  1. ajax jsonp

    there jsonp (json padding), communication technique javascript programs provide method request data server in different domain. @ documentation of jquery.getjson() , scroll down jsonp section.

    if url includes string "callback=?" (or similar, defined server-side api), request treated jsonp instead. see discussion of jsonp data type in $.ajax() more details.

  2. http request

    simply use net::http class:

    require 'net/http' require 'json'  url = uri.parse('http://video_tak.com/courses/get_course/1') req = net::http::get.new(url.to_s) res = net::http.start(url.host, url.port) |http|   http.request(req) end course_json = json.parse(res.body) 

    if provide methods model convert json domain object of yours, can take there.


rpc

you can use rpc invoke methods between different ruby processes, although recommend least not want omit it. there several remote procedure call (rpc) libraries. ruby standard library provides drb, there implementations based on ruby on rails, instance rails-xmlrpc gem allows implement rpc based on xml-rpc protocol or alternative protocol using json json-rpcj

you find more libraries when searching rails rpc. whatever library pick, concrete solution differ.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -