{"action":"created","issue":{"url":"https://api.github.com/repos/rails/rails/issues/18546","labels_url":"https://api.github.com/repos/rails/rails/issues/18546/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/18546/comments","events_url":"https://api.github.com/repos/rails/rails/issues/18546/events","html_url":"https://github.com/rails/rails/pull/18546","id":54500605,"number":18546,"title":"A shortcut to setup controller environment","user":{"login":"brainopia","id":386,"avatar_url":"https://avatars.githubusercontent.com/u/386?v=3","gravatar_id":"","url":"https://api.github.com/users/brainopia","html_url":"https://github.com/brainopia","followers_url":"https://api.github.com/users/brainopia/followers","following_url":"https://api.github.com/users/brainopia/following{/other_user}","gists_url":"https://api.github.com/users/brainopia/gists{/gist_id}","starred_url":"https://api.github.com/users/brainopia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brainopia/subscriptions","organizations_url":"https://api.github.com/users/brainopia/orgs","repos_url":"https://api.github.com/users/brainopia/repos","events_url":"https://api.github.com/users/brainopia/events{/privacy}","received_events_url":"https://api.github.com/users/brainopia/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rails/rails/labels/actionpack","name":"actionpack","color":"FFF700"},{"url":"https://api.github.com/repos/rails/rails/labels/actionview","name":"actionview","color":"d7e102"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/rails/rails/milestones/34","labels_url":"https://api.github.com/repos/rails/rails/milestones/34/labels","id":665192,"number":34,"title":"5.0.0","description":null,"creator":{"login":"rafaelfranca","id":47848,"avatar_url":"https://avatars.githubusercontent.com/u/47848?v=3","gravatar_id":"","url":"https://api.github.com/users/rafaelfranca","html_url":"https://github.com/rafaelfranca","followers_url":"https://api.github.com/users/rafaelfranca/followers","following_url":"https://api.github.com/users/rafaelfranca/following{/other_user}","gists_url":"https://api.github.com/users/rafaelfranca/gists{/gist_id}","starred_url":"https://api.github.com/users/rafaelfranca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rafaelfranca/subscriptions","organizations_url":"https://api.github.com/users/rafaelfranca/orgs","repos_url":"https://api.github.com/users/rafaelfranca/repos","events_url":"https://api.github.com/users/rafaelfranca/events{/privacy}","received_events_url":"https://api.github.com/users/rafaelfranca/received_events","type":"User","site_admin":false},"open_issues":95,"closed_issues":41,"state":"open","created_at":"2014-05-21T00:58:22Z","updated_at":"2015-01-21T22:07:12Z","due_on":null,"closed_at":null},"comments":15,"created_at":"2015-01-15T20:35:30Z","updated_at":"2015-01-22T01:04:03Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rails/rails/pulls/18546","html_url":"https://github.com/rails/rails/pull/18546","diff_url":"https://github.com/rails/rails/pull/18546.diff","patch_url":"https://github.com/rails/rails/pull/18546.patch"},"body":"Related to #18409\r\n\r\nSome reiteration first.\r\nWhat we looking for is an easy way to render templates outside of controllers.\r\n\r\nView templates are rendered as part of request-response cycle. There are easy cases when templates would not depend on anything except ivars from controller, but a lot of templates use helpers that depend on request environment in one form or another.\r\n\r\nSometimes helpers depend on stuff that's easy to setup, like a scheme, host or script name. But request environment is also used by gems to hold transient data associated with current request (e.g., helpers from devise would raise an exception if request environment hasn't been prepared by its middleware).\r\n\r\nTherefore two use-cases arise.\r\n- Ability to render templates in custom request environment.\r\n- Ability to render templates in an environment that was passed through middleware stack. \r\n\r\nThis PR deals with the first part.\r\n\r\n```ruby\r\n# this would setup following environment keys: REQUEST_METHOD, SERVER_NAME, SERVER_PORT, QUERY_STRING, PATH_INFO, rack.url_scheme, HTTPS, rack.input\r\nFooController.setup_for(_uri_).render_to_string _render_options_  \r\n\r\n# or more detailed setup\r\ncontroller = FooController.setup_for _uri_, script_name: 'bar', method: 'post', 'env_key' => 'baz'\r\n... # configure controller instance a bit\r\ncontroller.render_to_string _render_options_ \r\n```\r\n\r\nWhere `_render_options_` could contain `assigns: { a: 'b' }` to set ivars.\r\n\r\n/cc @dhh "},"comment":{"url":"https://api.github.com/repos/rails/rails/issues/comments/70953644","html_url":"https://github.com/rails/rails/pull/18546#issuecomment-70953644","issue_url":"https://api.github.com/repos/rails/rails/issues/18546","id":70953644,"user":{"login":"dhh","id":2741,"avatar_url":"https://avatars.githubusercontent.com/u/2741?v=3","gravatar_id":"","url":"https://api.github.com/users/dhh","html_url":"https://github.com/dhh","followers_url":"https://api.github.com/users/dhh/followers","following_url":"https://api.github.com/users/dhh/following{/other_user}","gists_url":"https://api.github.com/users/dhh/gists{/gist_id}","starred_url":"https://api.github.com/users/dhh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dhh/subscriptions","organizations_url":"https://api.github.com/users/dhh/orgs","repos_url":"https://api.github.com/users/dhh/repos","events_url":"https://api.github.com/users/dhh/events{/privacy}","received_events_url":"https://api.github.com/users/dhh/received_events","type":"User","site_admin":false},"created_at":"2015-01-22T01:04:03Z","updated_at":"2015-01-22T01:04:03Z","body":"Looks good to me! Great work, guys. "}}