Module: Superview::Actions
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/superview/actions.rb
Overview
Include in controllers to map action names to class names. This makes it possible to embed Phlex components directly into Rails controllers without having to go through other templating systems like Erb.
Instance methods will be assigned to views that have ‘attr_accessor` methods.
Consider a blog post controller:
“‘ruby class PostsController < ApplicationController
include Superview::Actions
before_action :load_post
class Show < ApplicationComponent
attr_accessor :post
def view_template(&)
h1 { @post.title }
div(class: "prose") { @post.body }
end
end
private
def load_post
@post = Post.find(params[:id])
end
end “‘
The ‘@post` variable gets set in the `Show` view class via `Show#post=`.