Class: ActionView::Base
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
ActionDispatch::DebugView
|
|
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
self,
Helpers::RenderingHelper ,
Helpers::NumberHelper ,
Helpers::JavaScriptHelper ,
Helpers::FormOptionsHelper ,
Helpers::FormHelper ,
RecordIdentifier ,
Helpers::FormTagHelper ,
Helpers::TextHelper ,
Helpers::SanitizeHelper ,
Helpers::UrlHelper ,
Helpers::DateHelper ,
Helpers::AssetTagHelper ,
Helpers::TagHelper ,
Helpers::CaptureHelper ,
Helpers::AssetUrlHelper ,
::ActiveSupport::Benchmarkable ,
::ERB::Util ,
Context
|
|
Inherits: | Object |
Defined in: | actionview/lib/action_view/base.rb |
Overview
Action View templates can be written in several ways. If the template file has a .erb
extension, then it uses the erubi template system which can embed Ruby into an HTML document. If the template file has a .builder
extension, then Jim Weirich’s Builder::XmlMarkup
library is used.
ERB
You trigger ::ERB
by using embeddings such as <% %>
, <% -%>
, and <%= %>
. The <%= %>
tag set is used when you want output. Consider the following loop for names:
<b>Names of all the people</b>
<% @people.each do |person| %>
Name: <%= person.name %><br/>
<% end %>
The loop is set up in regular embedding tags <% %>
, and the name is written using the output embedding tag <%= %>
. Note that this is not just a usage suggestion. Regular output functions like print or puts won’t work with ::ERB
templates. So this would be wrong:
<%# WRONG %>
Hi, Mr. <% puts "Frodo" %>
If you absolutely must write from within a function use concat
.
When on a line that only contains whitespaces except for the tag, <% %>
suppresses leading and trailing whitespace, including the trailing newline. <% %>
and <%- -%>
are the same. Note however that <%= %>
and <%= -%>
are different: only the latter removes trailing whitespaces.
Using sub templates
Using sub templates allows you to sidestep tedious replication and extract common display structures in shared templates. The classic example is the use of a header and footer (even though the Action Pack-way would be to use Layouts
):
<%= render "shared/header" %>
Something really specific and terrific
<%= render "shared/footer" %>
As you see, we use the output embeddings for the render methods. The render call itself will just return a string holding the result of the rendering. The output embedding writes it to the current template.
But you don’t have to restrict yourself to static includes. Templates can share variables amongst themselves by using instance variables defined using the regular embedding tags. Like this:
<% @page_title = "A Wonderful Hello" %>
<%= render "shared/header" %>
Now the header can pick up on the @page_title
variable and use it for outputting a title tag:
<title><%= @page_title %></title>
Passing local variables to sub templates
You can pass local variables to sub templates by using a hash with the variable names as keys and the objects as values:
<%= render "shared/header", { headline: "Welcome", person: person } %>
These can now be accessed in shared/header
with:
Headline: <%= headline %>
First name: <%= person.first_name %>
The local variables passed to sub templates can be accessed as a hash using the local_assigns
hash. This lets you access the variables as:
Headline: <%= local_assigns[:headline] %>
This is useful in cases where you aren’t sure if the local variable has been assigned. Alternatively, you could also use defined? headline
to first check if the variable has been assigned before using it.
Template caching
By default, ::Rails
will compile each template to a method in order to render it. When you alter a template, ::Rails
will check the file’s modification time and recompile it in development mode.
Builder
Builder templates are a more programmatic alternative to ::ERB
. They are especially useful for generating XML content. An XmlMarkup object named xml
is automatically made available to templates with a .builder
extension.
Here are some basic examples:
xml.em("emphasized") # => <em>emphasized</em>
xml.em { xml.b("emph & bold") } # => <em><b>emph & bold</b></em>
xml.a("A Link", "href" => "http://onestepback.org") # => <a href="http://onestepback.org">A Link</a>
xml.target("name" => "compile", "option" => "fast") # => <target option="fast" name="compile"\>
# NOTE: order of attributes is not specified.
Any method with a block will be treated as an XML markup tag with nested markup in the block. For example, the following:
xml.div do
xml.h1(@person.name)
xml.p(@person.bio)
end
would produce something like:
<div>
<h1>David Heinemeier Hansson</h1>
<p>A product of Danish Design during the Winter of '79...</p>
</div>
Here is a full-length RSS example actually used on Basecamp:
xml.rss("version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/") do
xml.channel do
xml.title(@feed_title)
xml.link(@url)
xml.description "Basecamp: Recent items"
xml.language "en-us"
xml.ttl "40"
@recent_items.each do |item|
xml.item do
xml.title(item_title(item))
xml.description(item_description(item)) if item_description(item)
xml.pubDate(item_pubDate(item))
xml.guid(@person.firm.account.url + @recent_items.url(item))
xml.link(@person.firm.account.url + @recent_items.url(item))
xml.tag!("dc:creator", item. ) if item_has_creator?(item)
end
end
end
end
For more information on Builder please consult the source code.
Constant Summary
::ERB::Util
- Included
HTML_ESCAPE, HTML_ESCAPE_ONCE_REGEXP, JSON_ESCAPE, JSON_ESCAPE_REGEXP, TAG_NAME_FOLLOWING_REGEXP, TAG_NAME_REPLACEMENT_CHAR, TAG_NAME_START_REGEXP, TAG_NAME_START_REGEXP_SET
Helpers::AssetUrlHelper
- Included
ASSET_EXTENSIONS, ASSET_PUBLIC_DIRECTORIES, URI_REGEXP
Helpers::TagHelper
- Included
ARIA_PREFIXES, BOOLEAN_ATTRIBUTES, DATA_PREFIXES, PRE_CONTENT_STRINGS, TAG_TYPES
Helpers::DateHelper
- Included
MINUTES_IN_QUARTER_YEAR, MINUTES_IN_THREE_QUARTERS_YEAR, MINUTES_IN_YEAR
Helpers::UrlHelper
- Included
BUTTON_TAG_METHOD_VERBS, STRINGIFIED_COMMON_METHODS
RecordIdentifier
- Included
Helpers::JavaScriptHelper
- Included
Class Attribute Summary
- ._routes rw
- ._routes? ⇒ Boolean rw
-
.annotate_rendered_view_with_filenames
(also: #annotate_rendered_view_with_filenames)
rw
Annotate rendered view with file names.
-
.automatically_disable_submit_tag
(also: #automatically_disable_submit_tag)
rw
Specify whether submit_tag should automatically disable on click.
- .cache_template_loading rw
- .cache_template_loading=(value) rw
-
.default_formats
(also: #default_formats)
rw
Specify default_formats that can be rendered.
-
.field_error_proc
(also: #field_error_proc)
rw
Specify the proc used to decorate input tags that refer to attributes with errors.
- .logger rw
- .logger? ⇒ Boolean rw
- .prefix_partial_path_with_controller_namespace rw
- .prefix_partial_path_with_controller_namespace? ⇒ Boolean rw
-
.raise_on_missing_translations
(also: #raise_on_missing_translations)
rw
Specify whether an error should be raised for missing translations.
-
.streaming_completion_on_exception
(also: #streaming_completion_on_exception)
rw
How to complete the streaming when an exception occurs.
Class Method Summary
Instance Attribute Summary
- #_routes rw
- #_routes? ⇒ Boolean rw
- #annotate_rendered_view_with_filenames rw
- #assigns rw
- #automatically_disable_submit_tag rw
- #config rw
- #default_formats rw
- #field_error_proc rw
- #formats rw
- #locale rw
- #logger rw
- #logger? ⇒ Boolean rw
- #lookup_context readonly
- #prefix_partial_path_with_controller_namespace rw
- #prefix_partial_path_with_controller_namespace? ⇒ Boolean rw
- #raise_on_missing_translations rw
- #streaming_completion_on_exception rw
- #view_paths rw
- #view_renderer readonly
Helpers::FormHelper
- Included
Helpers::FormTagHelper
- Included
Helpers::AssetTagHelper
- Included
Context
- Included
Instance Method Summary
- #_run(method, template, locals, buffer, add_to_stack: true, &block)
- #compiled_method_container
- #in_rendering_context(options)
Helpers::RenderingHelper
- Included
#_layout_for | Overwrites _layout_for in the context object so it supports the case a block is passed to a partial. |
#render | Returns the result of a render that’s dictated by the options hash. |
Helpers::NumberHelper
- Included
#number_to_currency | Formats a |
#number_to_human | Pretty prints (formats and approximates) a number in a way it is more readable by humans (e.g.: 1200000000 becomes “1.2 Billion”). |
#number_to_human_size | Formats the bytes in |
#number_to_percentage | Formats a |
#number_to_phone | Formats a |
#number_with_delimiter | Formats a |
#number_with_precision | Formats a |
Helpers::JavaScriptHelper
- Included
#escape_javascript | Escapes carriage returns and single and double quotes for JavaScript segments. |
#j | Alias for Helpers::JavaScriptHelper#escape_javascript. |
#javascript_tag | Returns a JavaScript tag with the |
Helpers::FormOptionsHelper
- Included
#collection_check_boxes | Returns check box tags for the collection of existing return values of |
#collection_radio_buttons | Returns radio button tags for the collection of existing return values of |
#collection_select | Returns |
#grouped_collection_select | Returns |
#grouped_options_for_select | Returns a string of |
#option_groups_from_collection_for_select | Returns a string of |
#options_for_select | Accepts a container (hash, array, enumerable, your type) and returns a string of option tags. |
#options_from_collection_for_select | Returns a string of option tags that have been compiled by iterating over the |
#select | Create a select tag and a series of contained option tags for the provided object and method. |
#time_zone_options_for_select | Returns a string of option tags for pretty much any time zone in the world. |
#time_zone_select | Returns select and option tags for the given object and method, using |
Helpers::FormHelper
- Included
#check_box | Returns a checkbox tag tailored for accessing a specified attribute (identified by |
#color_field | Returns a text_field of type “color”. |
#date_field | Returns a text_field of type “date”. |
#datetime_field | Returns a text_field of type “datetime-local”. |
#datetime_local_field | Alias for Helpers::FormHelper#datetime_field. |
#email_field | Returns a text_field of type “email”. |
#fields | Scopes input fields with either an explicit scope or model. |
#fields_for | Creates a scope around a specific model object like form_for, but doesn’t create the form tags themselves. |
#file_field | Returns a file upload input tag tailored for accessing a specified attribute (identified by |
#form_for | Creates a form that allows the user to create or update the attributes of a specific model object. |
#form_with | Creates a form tag based on mixing URLs, scopes, or models. |
#hidden_field | Returns a hidden input tag tailored for accessing a specified attribute (identified by |
#label | Returns a label tag tailored for labelling an input field for a specified attribute (identified by |
#month_field | Returns a text_field of type “month”. |
#number_field | Returns an input tag of type “number”. |
#password_field | Returns an input tag of the “password” type tailored for accessing a specified attribute (identified by |
#phone_field | Alias for Helpers::FormHelper#telephone_field. |
#radio_button | Returns a radio button tag for accessing a specified attribute (identified by |
#range_field | Returns an input tag of type “range”. |
#search_field | Returns an input of type “search” for accessing a specified attribute (identified by |
#telephone_field | Returns a text_field of type “tel”. |
#text_area | Returns a textarea opening and closing tag set tailored for accessing a specified attribute (identified by |
#text_field | Returns an input tag of the “text” type tailored for accessing a specified attribute (identified by |
#time_field | Returns a text_field of type “time”. |
#url_field | Returns a text_field of type “url”. |
#week_field | Returns a text_field of type “week”. |
RecordIdentifier
- Included
#dom_class | The DOM class convention is to use the singular form of an object or class. |
#dom_id | The DOM id convention is to use the singular form of an object or class with the id following an underscore. |
#record_key_for_dom_id | Returns a string representation of the key attribute(s) that is suitable for use in an HTML DOM id. |
Helpers::FormTagHelper
- Included
#button_tag | Creates a button element that defines a |
#check_box_tag | Creates a check box form input tag. |
#color_field_tag | Creates a text field of type “color”. |
#date_field_tag | Creates a text field of type “date”. |
#datetime_field_tag | Creates a text field of type “datetime-local”. |
#datetime_local_field_tag | Alias for Helpers::FormTagHelper#datetime_field_tag. |
#email_field_tag | Creates a text field of type “email”. |
#field_set_tag | Creates a field set for grouping HTML form elements. |
#file_field_tag | Creates a file upload field. |
#form_tag | Starts a form tag that points the action to a URL configured with |
#hidden_field_tag | Creates a hidden form input field used to transmit data that would be lost due to HTTP’s statelessness or data that should be hidden from the user. |
#image_submit_tag | Displays an image which when clicked will submit the form. |
#label_tag | Creates a label element. |
#month_field_tag | Creates a text field of type “month”. |
#number_field_tag | Creates a number field. |
#password_field_tag | Creates a password field, a masked text field that will hide the users input behind a mask character. |
#phone_field_tag | Alias for Helpers::FormTagHelper#telephone_field_tag. |
#radio_button_tag | Creates a radio button; use groups of radio buttons named the same to allow users to select from a group of options. |
#range_field_tag | Creates a range form element. |
#search_field_tag | Creates a text field of type “search”. |
#select_tag | Creates a dropdown selection box, or if the |
#submit_tag | Creates a submit button with the text |
#telephone_field_tag | Creates a text field of type “tel”. |
#text_area_tag | Creates a text input area; use a textarea for longer text inputs such as blog posts or descriptions. |
#text_field_tag | Creates a standard text field; use these text fields to input smaller chunks of text like a username or a search query. |
#time_field_tag | Creates a text field of type “time”. |
#url_field_tag | Creates a text field of type “url”. |
#utf8_enforcer_tag | Creates the hidden UTF8 enforcer tag. |
#week_field_tag | Creates a text field of type “week”. |
Helpers::TextHelper
- Included
#concat | The preferred method of outputting text in your views is to use the <%= “text” %> eRuby syntax. |
#current_cycle | Returns the current cycle string after a cycle has been started. |
#cycle | Creates a Cycle object whose to_s method cycles through elements of an array every time it is called. |
#excerpt | Extracts an excerpt from |
#highlight | Highlights one or more |
#pluralize | Attempts to pluralize the |
#reset_cycle | Resets a cycle so that it starts from the first element the next time it is called. |
#safe_concat, | |
#simple_format | Returns |
#truncate | Truncates a given |
#word_wrap | Wraps the |
Helpers::SanitizeHelper
- Included
#sanitize | Sanitizes HTML input, stripping all but known-safe tags and attributes. |
#sanitize_css | Sanitizes a block of CSS code. |
#strip_links | Strips all link tags from |
#strip_tags | Strips all HTML tags from |
Helpers::UrlHelper
- Included
#button_to | Generates a form containing a single button that submits to the URL created by the set of |
#link_to | Creates an anchor element of the given |
#link_to_if | Creates a link tag of the given |
#link_to_unless | Creates a link tag of the given |
#link_to_unless_current | Creates a link tag of the given |
#mail_to | Creates a mailto link tag to the specified |
#phone_to | Creates a TEL anchor link tag to the specified |
#sms_to | Creates an SMS anchor link tag to the specified |
Helpers::DateHelper
- Included
#date_select | Returns a set of select tags (one for year, month, and day) pre-selected for accessing a specified date-based attribute (identified by |
#datetime_select | Returns a set of select tags (one for year, month, day, hour, and minute) pre-selected for accessing a specified datetime-based attribute (identified by |
#distance_of_time_in_words | Reports the approximate distance in time between two |
#distance_of_time_in_words_to_now | Alias for Helpers::DateHelper#time_ago_in_words. |
#select_date | Returns a set of HTML select-tags (one for year, month, and day) pre-selected with the |
#select_datetime | Returns a set of HTML select-tags (one for year, month, day, hour, minute, and second) pre-selected with the |
#select_day | Returns a select tag with options for each of the days 1 through 31 with the current day selected. |
#select_hour | Returns a select tag with options for each of the hours 0 through 23 with the current hour selected. |
#select_minute | Returns a select tag with options for each of the minutes 0 through 59 with the current minute selected. |
#select_month | Returns a select tag with options for each of the months January through December with the current month selected. |
#select_second | Returns a select tag with options for each of the seconds 0 through 59 with the current second selected. |
#select_time | Returns a set of HTML select-tags (one for hour and minute). |
#select_year | Returns a select tag with options for each of the five years on each side of the current, which is selected. |
#time_ago_in_words | Like |
#time_select | Returns a set of select tags (one for hour, minute and optionally second) pre-selected for accessing a specified time-based attribute (identified by |
#time_tag | Returns an HTML time tag for the given date or time. |
Helpers::AssetTagHelper
- Included
#audio_tag | Returns an HTML audio tag for the |
#auto_discovery_link_tag | Returns a link tag that browsers and feed readers can use to auto-detect an RSS, Atom, or JSON feed. |
#favicon_link_tag | Returns a link tag for a favicon managed by the asset pipeline. |
#image_tag | Returns an HTML image tag for the |
#javascript_include_tag | Returns an HTML script tag for each of the |
#preload_link_tag | Returns a link tag that browsers can use to preload the |
#stylesheet_link_tag | Returns a stylesheet link tag for the sources specified as arguments. |
#video_tag | Returns an HTML video tag for the |
Helpers::TagHelper
- Included
#cdata_section | Returns a CDATA section with the given |
#class_names | Alias for Helpers::TagHelper#token_list. |
#content_tag | Returns an HTML block tag of type |
#escape_once | Returns an escaped version of |
#tag | Returns an HTML tag. |
#token_list | Returns a string of tokens built from |
Helpers::CaptureHelper
- Included
#capture | The capture method extracts part of a template as a |
#content_for | Calling |
#content_for? |
|
#provide | The same as |
Helpers::AssetUrlHelper
- Included
#asset_path | This is the entry point for all assets. |
#asset_url | Computes the full URL to an asset in the public directory. |
#audio_path | Computes the path to an audio asset in the public audios directory. |
#audio_url | Computes the full URL to an audio asset in the public audios directory. |
#compute_asset_extname | Compute extname to append to asset path. |
#compute_asset_host | Pick an asset host for this source. |
#compute_asset_path | Computes asset path to public directory. |
#font_path | Computes the path to a font asset. |
#font_url | Computes the full URL to a font asset. |
#image_path | Computes the path to an image asset. |
#image_url | Computes the full URL to an image asset. |
#javascript_path | Computes the path to a JavaScript asset in the public javascripts directory. |
#javascript_url | Computes the full URL to a JavaScript asset in the public javascripts directory. |
#path_to_asset | Alias for Helpers::AssetUrlHelper#asset_path. |
#path_to_audio | Alias for Helpers::AssetUrlHelper#audio_path. |
#path_to_font | Alias for Helpers::AssetUrlHelper#font_path. |
#path_to_image | Alias for Helpers::AssetUrlHelper#image_path. |
#path_to_javascript | Alias for Helpers::AssetUrlHelper#javascript_path. |
#path_to_stylesheet | Alias for Helpers::AssetUrlHelper#stylesheet_path. |
#path_to_video | Alias for Helpers::AssetUrlHelper#video_path. |
#public_compute_asset_path | Alias for Helpers::AssetUrlHelper#compute_asset_path. |
#stylesheet_path | Computes the path to a stylesheet asset in the public stylesheets directory. |
#stylesheet_url | Computes the full URL to a stylesheet asset in the public stylesheets directory. |
#url_to_asset | Alias for Helpers::AssetUrlHelper#asset_url. |
#url_to_audio | Alias for Helpers::AssetUrlHelper#audio_url. |
#url_to_font | Alias for Helpers::AssetUrlHelper#font_url. |
#url_to_image | Alias for Helpers::AssetUrlHelper#image_url. |
#url_to_javascript | Alias for Helpers::AssetUrlHelper#javascript_url. |
#url_to_stylesheet | Alias for Helpers::AssetUrlHelper#stylesheet_url. |
#url_to_video | Alias for Helpers::AssetUrlHelper#video_url. |
#video_path | Computes the path to a video asset in the public videos directory. |
#video_url | Computes the full URL to a video asset in the public videos directory. |
::ActiveSupport::Benchmarkable
- Included
#benchmark | Allows you to measure the execution time of a block in a template and records the result to the log. |
Context
- Included
#_layout_for | Encapsulates the interaction with the view flow so it returns the correct buffer on |
#_prepare_context | Prepares the context by setting the appropriate instance variables. |
Class Attribute Details
._routes (rw)
[ GitHub ]# File 'actionview/lib/action_view/base.rb', line 168
class_attribute :_routes
._routes? ⇒ Boolean
(rw)
[ GitHub ]
# File 'actionview/lib/action_view/base.rb', line 168
class_attribute :_routes
.annotate_rendered_view_with_filenames (rw) Also known as: #annotate_rendered_view_with_filenames
Annotate rendered view with file names
# File 'actionview/lib/action_view/base.rb', line 166
cattr_accessor :annotate_rendered_view_with_filenames, default: false
.automatically_disable_submit_tag (rw) Also known as: #automatically_disable_submit_tag
Specify whether submit_tag should automatically disable on click
# File 'actionview/lib/action_view/base.rb', line 163
cattr_accessor :automatically_disable_submit_tag, default: true
.cache_template_loading (rw)
[ GitHub ]# File 'actionview/lib/action_view/base.rb', line 174
def cache_template_loading ActionView::Resolver.caching? end
.cache_template_loading=(value) (rw)
[ GitHub ]# File 'actionview/lib/action_view/base.rb', line 178
def cache_template_loading=(value) ActionView::Resolver.caching = value end
.default_formats (rw) Also known as: #default_formats
Specify default_formats that can be rendered.
# File 'actionview/lib/action_view/base.rb', line 157
cattr_accessor :default_formats
.field_error_proc (rw) Also known as: #field_error_proc
Specify the proc used to decorate input tags that refer to attributes with errors.
# File 'actionview/lib/action_view/base.rb', line 145
cattr_accessor :field_error_proc, default: Proc.new { |html_tag, instance| "<div class=\"field_with_errors\">#{html_tag}</div>".html_safe }
.logger (rw)
[ GitHub ]# File 'actionview/lib/action_view/base.rb', line 169
class_attribute :logger
.logger? ⇒ Boolean
(rw)
[ GitHub ]
# File 'actionview/lib/action_view/base.rb', line 169
class_attribute :logger
.prefix_partial_path_with_controller_namespace (rw)
[ GitHub ]# File 'actionview/lib/action_view/base.rb', line 154
class_attribute :prefix_partial_path_with_controller_namespace, default: true
.prefix_partial_path_with_controller_namespace? ⇒ Boolean
(rw)
[ GitHub ]
# File 'actionview/lib/action_view/base.rb', line 154
class_attribute :prefix_partial_path_with_controller_namespace, default: true
.raise_on_missing_translations (rw) Also known as: #raise_on_missing_translations
Specify whether an error should be raised for missing translations
# File 'actionview/lib/action_view/base.rb', line 160
cattr_accessor :raise_on_missing_translations, default: false
.streaming_completion_on_exception (rw) Also known as: #streaming_completion_on_exception
How to complete the streaming when an exception occurs. This is our best guess: first try to close the attribute, then the tag.
# File 'actionview/lib/action_view/base.rb', line 149
cattr_accessor :streaming_completion_on_exception, default: %("><script>window.location = "/500.html"</script></html>)
Class Method Details
.empty
[ GitHub ]# File 'actionview/lib/action_view/base.rb', line 216
def self.empty with_view_paths([]) end
.with_context(context, assigns = {}, controller = nil)
[ GitHub ].with_view_paths(view_paths, assigns = {}, controller = nil)
[ GitHub ]# File 'actionview/lib/action_view/base.rb', line 220
def self.with_view_paths(view_paths, assigns = {}, controller = nil) with_context ActionView::LookupContext.new(view_paths), assigns, controller end
Instance Attribute Details
#_routes (rw)
[ GitHub ]# File 'actionview/lib/action_view/base.rb', line 168
class_attribute :_routes
#_routes? ⇒ Boolean
(rw)
[ GitHub ]
# File 'actionview/lib/action_view/base.rb', line 168
class_attribute :_routes
#annotate_rendered_view_with_filenames (rw)
[ GitHub ]# File 'actionview/lib/action_view/base.rb', line 166
cattr_accessor :annotate_rendered_view_with_filenames, default: false
#assigns (rw)
[ GitHub ]# File 'actionview/lib/action_view/base.rb', line 206
attr_internal :config, :assigns
#automatically_disable_submit_tag (rw)
[ GitHub ]# File 'actionview/lib/action_view/base.rb', line 163
cattr_accessor :automatically_disable_submit_tag, default: true
#config (rw)
[ GitHub ]# File 'actionview/lib/action_view/base.rb', line 206
attr_internal :config, :assigns
#default_formats (rw)
[ GitHub ]# File 'actionview/lib/action_view/base.rb', line 157
cattr_accessor :default_formats
#field_error_proc (rw)
[ GitHub ]# File 'actionview/lib/action_view/base.rb', line 145
cattr_accessor :field_error_proc, default: Proc.new { |html_tag, instance| "<div class=\"field_with_errors\">#{html_tag}</div>".html_safe }
#formats (rw)
[ GitHub ]# File 'actionview/lib/action_view/base.rb', line 208
delegate :formats, :formats=, :locale, :locale=, :view_paths, :view_paths=, to: :lookup_context
#locale (rw)
[ GitHub ]# File 'actionview/lib/action_view/base.rb', line 208
delegate :formats, :formats=, :locale, :locale=, :view_paths, :view_paths=, to: :lookup_context
#logger (rw)
[ GitHub ]# File 'actionview/lib/action_view/base.rb', line 169
class_attribute :logger
#logger? ⇒ Boolean
(rw)
[ GitHub ]
# File 'actionview/lib/action_view/base.rb', line 169
class_attribute :logger
#lookup_context (readonly)
[ GitHub ]# File 'actionview/lib/action_view/base.rb', line 205
attr_reader :view_renderer, :lookup_context
#prefix_partial_path_with_controller_namespace (rw)
[ GitHub ]# File 'actionview/lib/action_view/base.rb', line 154
class_attribute :prefix_partial_path_with_controller_namespace, default: true
#prefix_partial_path_with_controller_namespace? ⇒ Boolean
(rw)
[ GitHub ]
# File 'actionview/lib/action_view/base.rb', line 154
class_attribute :prefix_partial_path_with_controller_namespace, default: true
#raise_on_missing_translations (rw)
[ GitHub ]# File 'actionview/lib/action_view/base.rb', line 160
cattr_accessor :raise_on_missing_translations, default: false
#streaming_completion_on_exception (rw)
[ GitHub ]# File 'actionview/lib/action_view/base.rb', line 149
cattr_accessor :streaming_completion_on_exception, default: %("><script>window.location = "/500.html"</script></html>)
#view_paths (rw)
[ GitHub ]# File 'actionview/lib/action_view/base.rb', line 208
delegate :formats, :formats=, :locale, :locale=, :view_paths, :view_paths=, to: :lookup_context
#view_renderer (readonly)
[ GitHub ]# File 'actionview/lib/action_view/base.rb', line 205
attr_reader :view_renderer, :lookup_context
Instance Method Details
#_run(method, template, locals, buffer, add_to_stack: true, &block)
[ GitHub ]# File 'actionview/lib/action_view/base.rb', line 243
def _run(method, template, locals, buffer, add_to_stack: true, &block) _old_output_buffer, _old_virtual_path, _old_template = @output_buffer, @virtual_path, @current_template @current_template = template if add_to_stack @output_buffer = buffer public_send(method, locals, buffer, &block) ensure @output_buffer, @virtual_path, @current_template = _old_output_buffer, _old_virtual_path, _old_template end
#compiled_method_container
# File 'actionview/lib/action_view/base.rb', line 252
def compiled_method_container raise NotImplementedError, <<~msg.squish Subclasses of ActionView::Base must implement `compiled_method_container` or use the class method `with_empty_template_cache` for constructing an ActionView::Base subclass that has an empty cache. msg end
#in_rendering_context(options)
[ GitHub ]# File 'actionview/lib/action_view/base.rb', line 260
def in_rendering_context( ) old_view_renderer = @view_renderer old_lookup_context = @lookup_context if !lookup_context.html_fallback_for_js && [:formats] formats = Array( [:formats]) if formats == [:js] formats << :html end @lookup_context = lookup_context.with_prepended_formats(formats) @view_renderer = ActionView::Renderer.new @lookup_context end yield @view_renderer ensure @view_renderer = old_view_renderer @lookup_context = old_lookup_context end