Class: Mack::Rendering::Type::Action

Inherits:
FileBase show all
Defined in:
lib/mack/rendering/type/action.rb

Overview

Used to render a template that’s relative to a controller.

Example:

class UsersController
  include Mack::Controller
  # /users/:id
  def show
    @user = User.first(params[:id])
  end
  # /users
  def index
    @users = User.all
    render(:action, :list)
  end
end

When some calls /users/1 the file: app/views/users/show.html.erb will be rendered. When some calls /users the file: app/views/users/list.html.erb will be rendered.

Instance Attribute Summary

Attributes inherited from Base

#view_template

Instance Method Summary collapse

Methods inherited from FileBase

#concat, #render_file

Methods inherited from Base

#allow_layout?, #capture, #controller_view_path, #find_engine, #find_file, #initialize, #method_missing

Constructor Details

This class inherits a constructor from Mack::Rendering::Type::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Mack::Rendering::Type::Base

Instance Method Details

#renderObject

See Mack::Rendering::Type::FileBase render_file for more information.

The path to the file is built like such:

app/views/#{controller name}/#{render_value || action name (show, index, etc...)}.#{format (html, xml, js, etc...)}.#{extension defined in the engine}

Example:

app/views/users/show.html.erb


30
31
32
33
# File 'lib/mack/rendering/type/action.rb', line 30

def render
  a_file = File.join(self.controller_view_path, "#{self._render_value}.#{self._options[:format]}")
  render_file(a_file)
end