/reports/generate_report를로드하면 레일스 앱에서 XML을 생성합니다.레일에 페이지로드하기
별도 페이지에서이 XML을 변수로 읽고 데이터베이스에 저장하고 싶습니다.
어떻게하면됩니까? /reports/generate_report.xml URI의 응답을 어떻게 든 변수로 스트리밍 할 수 있습니까? XML이 동일한 웹 응용 프로그램에서 생성 되었기 때문에 더 좋은 방법이 있을까요?
class AnotherController < ApplicationController
def archive_current
@output = # get XML output produced by /reports/generate_report
# save @output to the database
respond_to do |format|
format.html # inform the user of success or failure
end
end
end
가 해결 : 내 솔루션 (믈라덴 Jablanović 덕분에) :
을 다음class ReportsController < ApplicationController
def generate_report
respond_to do |format|
@products = Product.all
format.xml { render :layout => false }
end
end
end
나는 쓰기를 시도하고있는 작업은 다음과 같습니다
내 generate_report 작업입니다@output = render_to_string(:file => 'reports/generate_report.xml.builder')
다음 코드를 모델 클래스에서 사용했습니다.
이av = ActionView::Base.new(Rails::Configuration.new.view_path)
@output = av.render(:file => "reports/generate_report.xml.builder")
왜 데이터를 XML로 변환 한 다음 데이터베이스에 다시 저장하려고하는지 궁금합니다. – Salil
@ Salal : 이전 버전의 데이터를 버전 관리와 같은 종류의 데이터베이스에 저장하려고합니다. – titaniumdecoy