iframe - Rails app (production) interfacing with another rails app on same machine -
i created small application generates reports (mainly pdfs) sqlite3 database exported gnucash. separated app possibility of sharing other vfw posts using gnucash or stuck paper general ledger. call quasi api in reports can generated in both html , pdf or can send data. before separated it, had tried multiple database approach, adding sqlite3 database database.yaml along main postgresql database. worked made possibility of sharing difficult , little skeptical approach.
all fine pdfs (prawn generated). use restclient reports pdf server running on same machine on different port. example, generate general ledger controller action called:
def ledger_pdf resp = restclient.get "http://localhost:8600/ledgers/#{params[:id]}/ledger_pdf" send_data resp.body, filename: "ledger#{params[:id]}", type: "application/pdf", disposition: "inline" end
on pdf server, action responds
def ledger_pdf pdf = pdf::ledger.new(view_context,params) send_data pdf.render, filename: "ledger#{params[:id]}", type: "application/pdf", disposition: "inline" end
getting html version became little more challenging! on pdf server have 1 page menu lists reports available, date , others collection route. 'sharing' version needs reports , not have rails application other stuff. server stand alone running on box.
rather getting data , creating page on main application data, got menu pdf server in iframe tag. though working great when discovered that, in view:
<iframe src="http://localhost:8600/ledgers/" width="100%" height="100%" id="rails_iframe">error!</iframe>
was calling localhost:8600
on machine (which running development version , fooled me thinking working!) rather on production server. after researching discovered can't that. guess restclient call localhost:8600
hidden browser, iframe call not.
i guess can html versions using same restclient approach , return text/html , use nokogiri body/html , yield
somehow, if knew how that.
the html.slim simple , duplicate on main server after getting data, i'd have 2 code bases maintain.
another approach make real api , make public iframe approach work, trying avoid (authentication , that).
i guess question is, have approach or can refine or give me pointers on approaches.
you need add action 'pdf' server render menu:
def menu render json: {first: 'first/report', second: 'second/report'} end
and fetch menu main server (which facing users):
def menu resp = restclient.get ... # parse resp.body menu structure # convert json response pdf server html erb template @menu_items = ... end
then have route on main server pass information collection server well, like:
get "reports/:collection/:date/:report", to: 'reports#fetch' # in controller def fetch resp = restclient.get "...#{params[:collection]}/#{params[:date]}/#{params[:report]} ... end
personally, wouldn't use rails server pdf generation. would've used cron script run ruby script pdf generation, , upload them s3 or other cloud storage. rails server would've return link s3 file.
Comments
Post a Comment