Using rack middlewares directly from Rails actions
I have a Rack middleware that I want to embed in my Rails app. By embed, I mean injecting it into my application's layout, so that <%= yield %>
contains the body of what the Rack app returns.
Here's my current solution:
def show
result = MyRackApp.new.call(request.env)
render :text => result[2].read, :status => result[0]
end
This is problematic, though, since result[2]
does not always have a IO style read
method, it might be a Rack::File
for example.
So, how do I make a Rails controller render a [200, {}, some_io_object]
type Rack response? Alternatively, can I do it开发者_JAVA技巧 the other way around with a Rack middleware that is able to render Rails layouts?
I'm using Rails 3.0.9.
If you want to use a rack application from Rails, you have to mount it from your router (routes.rb)
AppName::Application.routes.draw do
# Other routes
mount MyRackApp => "/pathToReachIt"
# root to: '...'
end
More info here
精彩评论