Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The first two things to keep in mind in order to integrate with Rails is
that
WebPipe
instances are Rack applications and that rails router canperfectly dispatch to a rack application. For example:
In order to do something like the previous example you don't need to enable
this extension. Notice that rails took care of dispatching the request to our
WebPipe
rack application, which was then responsible for generating theresponse. In this case, it used a simple call to
#set_response_body
.It's quite possible that you don't need more than that in terms of rails
integration. Of course, surely you want something more elaborate to generate
responses. For that, you can use the view or template system you like. One
option that will play specially well here is
dry-view
, whichintegrates
itself easily with Rails. Furthermore, we have a tailored
dry_view
extension.You need to use this extension if:
action_view
as rendering system.WebPipe
application.WebPipe
application.Rails responsibilities for controlling the request/response cycle and the
rendering process are a little bit tangled. For this reason, even if you
want to use
WebPipe
applications instead of Rails controller actions youstill have to use the typical top
ApplicationController
in order to definesome behaviour for the view layer:
app/views/
templates are looked up.By default, the controller in use is
ActionController::Base
, which means thatno layout is applied and only built-in helpers (for example,
number_as_currency
) are available. You can change it via the:rails_controller
configuration option.The main method that this extension adds to
WebPipe::Conn
is#render
,which just delegates to the Rails
implementation
as you'd do in a typical rails controller. Remember that you can provide
template instance variables through the keyword
:assigns
.Notice that we used the keyword
template:
instead of taking advantage ofautomatic template lookup. We did that way so that we don't have to create also
an
ArticlesController
, but it's up to you.Besides, this extension provides with two other methods:
url_helpers
returns Rails router urlhelpers.
helpers
returns the associated controllerhelpers.
In all the examples we have supposed that we are putting
WebPipe
applicationswithin
app/controllers/
directory. However, remember you can put themwherever you like as long as you respect rails
autoload_paths
.Here you have a link to a very simple and contrived example of a rails
application integrating
web_pipe
:https://github.com/waiting-for-dev/rails-web_pipe