-
-
Notifications
You must be signed in to change notification settings - Fork 43
action-view interoperability #302
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
Conversation
such that one can leave out the call to `render` or `responder_for` in the controller alltogether.
…ActiveSupport::SafeBuffer`
Scenario:
|
suggested by #303
# In this example, the `clients/bookings#step1` action will render | ||
# `Pages::Clients::Bookings::Step1`. | ||
# | ||
def default_render(*args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this approach too much. "index" and "show" should not be translated to the plural or singular of the controller name. all actions should be treated equally like: "Pages::Clients::Bookings::Step1", "Pages::Clients::Bookings::Index", "Pages::Clients::Bookings::Index"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cross-linking discussion on slack: https://matestack.slack.com/archives/GPV5T7T4N/p1578783962000100?thread_ts=1578140173.014600&cid=GPV5T7T4N
while supporting a couple of other naming schemes. #302
Issue #302: action-view interoperability
Changes
render
method, commonly used in rails, is extended to support matestack pages. (42d24fa)link_to
, which return anActiveSupport::SafeBuffer
, are implicitly wrapped in aplain
component when used in matestack components or pages. (ba93b32)Notes
The changes proposed in this pull request intend to make matestack easier to use by newcomers.
Exposing the view context
When rendering matestack pages or controllers from a controller, which includes the
Matestack::Ui::Core::ApplicationHelper
, the controller'sview_context
is passed as context to the matestack object, which exposes the view context to its components. This way, helpers and other methods exposed by the controller to the vanilla-rails views, can also be used from matestack pages or components.For example, the
current_user
method from devise, thecan?
method from cancancan, or methods exposed by decent_exposure (bookings
in the example below) can be used in matestack objects.Explicit rendering of matestack pages
The
render
method of rails is extended to also support matestack pages. This way, therender
method can be used instead ofresponder_for
in controllers.Implicit rendering of matestack pages
In rails, when a controller action has no explicit
render
call, the view to render is inferred from the controller name and the controller action. This pull request extends this mechanism to support matestack pages.The
index
action looks for a matestack page matching the controller namespace (Admins
) and the controller name in plural (Bookings
). Theshow
action looks for a matestack page matching the controller namespace and the controller name in singular (Booking
).Implicitly rendering legacy helpers in plain components
Using vanilla-rails helpers like
link_to
in matestack components or pages, does not raise an error, but does not render the helpers' output. For example:One could render these vanilla-rails helpers by prefixing them with a
plain
component (plain link_to "Sign in"
).This pull request prefixes
link_to
and other helpers returning anActiveSupport::SafeBuffer
implicitly withplain
, making the above example work.