Posted over 7 years ago. Visible to the public.

Let a Rails 3 application make a request to itself

Ever wondered how Rails talks to itself in a Cucumber feature? In Rails 3 you can do it like this:

Copy
def rack_env(path) { "rack.input" => {}, "PATH_INFO"=>"#{path}", "REQUEST_METHOD"=>"GET" } end request = rack_env('/users/new') response = Rails.application.call(request) status, headers, body = response puts status # e.g. 200 puts headers.inspect # hash of headers puts body.body # html of response body

Instead of Rails.application you can also call any Rack application.

Once an application no longer requires constant development, it needs periodic maintenance for stable and secure operation. makandra offers monthly maintenance contracts that let you focus on your business while we make sure the lights stay on.

Owner of this card:

Avatar
Henning Koch
Last edit:
almost 7 years ago
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Henning Koch to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more