문제

is possible to generate an HTML page using Ruby on Rails framework without using a webserver? I want do something like this:

html = RailsHTMLGenerator.generate('path/to/rails/root', '/posts/540')
puts html

The first parameter is the Rails.root, the second is the HTTP path, and the function return the HTML of that page as string.

Someone can tell me how to do this? Ty.

도움이 되었습니까?

해결책

I've found a solution:

require '/path/to/application.rb'
app = APPName::Application.initialize!
session = ActionDispatch::Integration::Session.new(app)
session.get '/'
puts session.body

다른 팁

Well, you can do that from the Rails console

app.get '/foo'

This is how the console is initialized in case you want to try this approach:

https://github.com/rails/rails/blob/master/railties/lib/rails/commands/console.rb

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top