New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make it easy to render templates outside of controllers #18409
Comments
this might be related to #11662. I also like to see this built into rails |
Yup, attacking the same issue.
|
@dhh as for the name, what about something like |
I'll take a look, if the issue is still unassigned. |
Go for it. |
Hmm, there's something to Anyway, @brainopia please do take a stab at this! |
What about |
Hmm. “Direct” is a nice word, but I don’t know if it necessarily implies any more clarity. At some point it is what we define it to be, and it doesn’t matter that much what it really is, I suppose.
|
Hello, David. I've been pondering about this feature. In the example above a request environment consists of An example of this would be Devise. A call to What if we'd have a class that could gather and return a request environment for a given URL by passing it through middleware stack but stopping at application routes. env = ActionDispatch::Middleware::Env.for 'https://basecamp.com/xxx/projects/yyy',
method: 'GET',
headers: { optional_headers } then it could be used as It would handle correctly setting all environment variables from your example ( And we can wrap Also regarding |
I like the idea of that! Please give that a go in a PR, and let's try it out. Be happy to test it in our Basecamp stuff. Thanks for working on this. |
Closed by #18546 |
What's the easiest way to get the similar behavior with Rails 4? I am trying to get actioncable-examples working with 4.2.5. |
@brainopia Was just reading your Medium post ;) Thanks for the link, will try it out! |
@dhh I've found myself at this issue after reviewing #18546 and some other related links. http://www.thegreatcodeadventure.com/using-action-controller-renderers-in-rails-5-with-devise/ What I'm not understanding is how this would ever work in a real world application. Your video on Rails 5 Action Cable shows off this code, but what you do is not really possible if you're using any authentication or anything that requires middleware like Devise. In the use case you've highlighted in your video, you are rendering views from an asynchronous worker. The only way this would be possible is to pass the request environment in which is basically impossible to serialize. Am I missing something? |
I don't use Devise, so don't know what that looks like. But you're just rendering the views, not the controller actions. You don't need to have all envs available to do that. If you need that, your code is too tangled. You can just pass the ivar/local vars that the specific template/partial needs. |
While templates depend on certain aspects from the controller to be rendered properly, you are often in a scenario where you might need to render something outside of a controller. Examples include jobs, auxiliary scripts, web sockets, etc.
For this purpose, I've been using a RenderMan class like follows:
In our application, we've further specialized this class into an ApplicationRenderer that looks like so:
It's used as such:
(This specialization is mostly just to show the justification of the SCRIPT_NAME munging).
I'd like to see RenderMan go into ActionView, or, if there's a simpler way to achieve the same, then that. I'd also like to find a new class name.
The text was updated successfully, but these errors were encountered: