SlideShare a Scribd company logo
1 of 50
In
RAILS
By,
Amal Subhash
AssociateSoftwareEngineer,
PIT Solutions,
Technopark,
Trivandrum.
Date: 12-06-2015
Action View
What is Action View?
Action View and Action Controller are the two
major components of Action Pack.

In Rails, web requests are handled by Action
Pack, which splits the work into a controller
part (performing the logic) and a view part
(rendering a template).

Typically, Action Controller will be concerned
with communicating with the database and
Using Action View with Rails
For each controller there is an associated directory
in the app/views directory which holds the
template files that make up the views associated
with that controller.
These files are used to display the view that results
from each controller action.
Example of view in scaffold
generator :
$ bin/rails generate scaffold article

[...]

invoke scaffold_controller

create
app/controllers/articles_controller.r
b

invoke erb

create app/views/articles
There is a naming convention for views in
Rails. Typically, the views share their
name with the associated controller action,
as you can see above.
For example, the index controller action of
the articles_controller.rb will use the
index.html.erb view file in the
app/views/articles directory.
The complete HTML returned to the client is
composed of a combination of this ERB
file, a layout template that wraps it, and all
the partials that the view may reference
Templates, Partials and
Layouts
Templates
Action View templates can be written in
several ways. If the template file has a .erb
extension then it uses a mixture of ERB
(Embedded Ruby) and HTML. If the template
file has a .builder extension then the
Builder::XmlMarkup library is used.
ERB
Within an ERB template, Ruby code can be
included using both <% %> and <%= %>
tags. The <% %> tags are used to execute
Ruby code that does not return anything,
such as conditions, loops or blocks, and
the <%= %> tags are used when you want
output.
Consider the following loop for names:
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")
Partials
Partial templates - usually just called "partials" - are
another device for breaking the rendering process
into more manageable chunks. With partials, you
can extract pieces of code from your templates to
separate files and also reuse them throughout your
templates.
Naming Partials
To render a partial as part of a view, you use
the render method within the view:
<%= render "menu" %>
This will render a file named _menu.html.erb
at that point within the view that is being
rendered. Note the leading underscore
character: partials are named with a leading
underscore to distinguish them from regular
views, even though they are referred to
without the underscore. This holds true even
when you're pulling in a partial from another
Layouts
Layouts can be used to render a common view
template around the results of Rails controller
actions.
Typically, a Rails application will have a couple of
layouts that pages will be rendered within.

For example, a site might have one layout for a
logged in user and another for the marketing or
sales side of the site.
Partial Layouts
Partials can have their own layouts applied to
them. These layouts are different from those
applied to a controller action, but they work in
a similar fashion.
Let's say we're displaying an article on a page
which should be wrapped in a div for display
purposes. Firstly, we'll create a new Article:
Article.create(body: 'Partial Layouts are cool!')
In the show template, we'll render the _article
partial wrapped in the box layout:
articles/_box.html.erb
<div class='box'>
<%= yield %>
</div>
The _article partial wraps the article's body
in a div with the id of the article using the
div_for helper:
this would output the following:
<div class='box'>
<div id='article_1'>
<p>Partial Layouts are cool!</p>
</div>
</div>
Overview of helpers
provided by Action View

RecordTagHelper
This module provides methods for
generating container tags, such as div, for
your record. This is the recommended way
of creating a container for render your
Active Record object, as it adds an
appropriate class and id attributes to that
container. You can then refer to those
containers easily by following the
content_tag_for
Renders a container tag that relates to your
Active Record Object.
For example, given @article is the object of
Article class, you can do:
<%= content_tag_for(:tr, @article) do %>
This will generate this HTML output:
<tr id="article_1234" class="article">
<td>Hello World!</td>
</tr>
div_for
This is actually a convenient method which
calls content_tag_for internally with :div as
the tag name. You can pass either an
Active Record object or a collection of
objects. For example:
<%= div_for(@article, class: "frontpage") do
%>
AssetTagHelper
This module provides methods for generating
HTML that links views to assets such as
images, JavaScript files, stylesheets, and
feeds.
By default, Rails links to these assets on the
current host in the public folder, but you can
direct Rails to link to assets from a
dedicated assets server by setting
config.action_controller.asset_host in the
register_javascript_expansion
Register one or more JavaScript files to be
included when symbol is passed to
javascript_include_tag. This method is
typically intended to be called from plugin
initialization to register JavaScript files that
the plugin installed in
vendor/assets/javascripts.
ActionView::Helpers::AssetTagHelper.regist
register_stylesheet_expansion
Register one or more stylesheet files to be
included when symbol is passed to
stylesheet_link_tag. This method is typically
intended to be called from plugin
initialization to register stylesheet files that
the plugin installed in
vendor/assets/stylesheets.
ActionView::Helpers::AssetTagHelper.register
_stylesheet_expansion monkey: ["head",
auto_discovery_link_tag
Returns a link tag that browsers and feed
readers can use to auto-detect an RSS or
Atom feed.
auto_discovery_link_tag(:rss,
"http://www.example.com/feed.rss", {title:
"RSS Feed"}) # =>
<link rel="alternate"
Image_path
Computes the path to an image asset in the
app/assets/images directory. Full paths from
the document root will be passed through.
Used internally by image_tag to build the
image path.
image_path("edit.png") # => /assets/edit.png
image_url
Computes the url to an image asset in the
app/assets/images directory. This will call
image_path internally and merge with your
current host or your asset host.
image_url("edit.png") # =>
http://www.example.com/assets/edit.png
javascript_include_tag
Returns an HTML script tag for each of the
sources provided. You can pass in the
filename (.js extension is optional) of
JavaScript files that exist in your
app/assets/javascripts directory for
inclusion into the current page or you can
pass the full path relative to your document
root.
javascript_include_tag "common" # =>
<script src="/assets/common.js"></script>
javascript_path
Computes the path to a JavaScript asset in
the app/assets/javascripts directory. If the
source filename has no extension, .js will be
appended. Full paths from the document
root will be passed through. Used internally
by javascript_include_tag to build the script
path.
stylesheet_link_tag
Returns a stylesheet link tag for the sources
specified as arguments. If you don't specify
an extension, .css will be appended
automatically.
stylesheet_link_tag "application" # => <link
href="/assets/application.css"
media="screen" rel="stylesheet" />
stylesheet_path
Computes the path to a stylesheet asset in the
app/assets/stylesheets directory. If the
source filename has no extension, .css will
be appended. Full paths from the document
root will be passed through. Used internally
by stylesheet_link_tag to build the stylesheet
path.
stylesheet_path "application" # =>
/assets/application.css
DateHelper
date_select
Returns a set of select tags (one for year,
month, and day) pre-selected for
accessing a specified date-based attribute.
date_select("article", "published_on")
datetime_select
Returns a set of select tags (one for year,
month, day, hour, and minute) pre-
selected for accessing a specified
distance_of_time_in_words
Reports the approximate distance in time
between two Time or Date objects or integers
as seconds. Set include_seconds to true if
you want more detailed approximations.
distance_of_time_in_words(Time.now,
Time.now + 15.seconds) # => less than a
minute
distance_of_time_in_words(Time.now,
Time.now + 15.seconds, include_seconds:
true) # => less than 20 seconds
select_datetime
Returns a set of HTML select-tags (one for year,
month, day, hour, and minute) pre-selected
with the datetime provided.
# Generates a datetime select that defaults to the
datetime provided (four days after today)
select_datetime(Time.now + 4.days)
# Generates a datetime select that defaults to
today (no specified datetime)

select_hour

select_minute

select_month

select_second

select_time

select_year

time_ago_in_words

time_select
FormHelper
Form helpers are designed to make
working with models much easier
compared to using just standard HTML
elements by providing a set of methods for
creating forms based on your models.
This helper generates the HTML for forms,
providing a method for each sort of input
(e.g., text, password, select, and so on).
form_for, gives you the ability to create a
form for a model instance; for example,
let's say that you have a model Person
and want to create a new instance of it:
<%= form_for @person, url: {action:
"create"} do |f| %>
<%= f.text_field :first_name %>
<%= f.text_field :last_name %>
<%= submit_tag 'Create' %>
<% end %>
The HTML generated for this would be:
The params object created when this form is
submitted would look like:
{"action" => "create", "controller" => "people",
"person" => {"first_name" => "William",
"last_name" => "Smith"}}
Check_box
Returns a checkbox tag tailored for
accessing a specified attribute.
file_field
Returns a file upload input tag tailored for
accessing a specified attribute.
file_field(:user, :avatar)
# => <input type="file" id="user_avatar"
name="user[avatar]" />
form_for
Creates a form and a scope around a
specific model object that is used as a base
for questioning about values for the fields.
hidden_field
Returns a hidden input tag tailored for
accessing a specified attribute.
hidden_field(:user, :token)
# => <input type="hidden" id="user_token"
name="user[token]"
value="#{@user.token}" />
label
Returns a label tag tailored for labelling an
password_field
Returns an input tag of the "password" type
tailored for accessing a specified attribute.
password_field(:login, :pass)
# => <input type="text" id="login_pass"
name="login[pass]" value="#{@login.pass}"
/>
radio_button
Returns a radio button tag for accessing a
specified attribute.
text_field
Returns an input tag of the "text" type tailored
for accessing a specified attribute.
text_field(:article, :title)
# => <input type="text" id="article_title"
name="article[title]" value="#{@article.title}"
/>
email_field
Returns an input tag of the "email" type
tailored for accessing a specified attribute.
url_field
Returns an input tag of the "url" type tailored
for accessing a specified attribute.
url_field(:user, :url)
# => <input type="url" id="user_url"
name="user[url]" value="#{@user.url}" />
FormOptionsHelper
Provides a number of methods for turning
different kinds of containers into a set of
option tags.
Example object structure for use with this
method:
class Article < ActiveRecord::Base
belongs_to :author
end
class Author < ActiveRecord::Base
has_many :articles
collection_radio_buttons
collection_check_boxes
country_options_for_select
country_select
option_groups_from_collection_for_select
options_for_select
options_from_collection_for_select
Select
Create a select tag and a series of contained
option tags for the provided object and
method.
Example:
select("article", "person_id", Person.all.collect
{|p| [ p.name, p.id ] }, {include_blank: true})
If @article.person_id is 1, this would become:
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
time_zone_options_for_select to generate
the list of option tags.
time_zone_select( "user", "time_zone")
FormTagHelper
Provides a number of methods for creating
form tags that don't rely on an Active
Record object assigned to the template like
FormHelper does. Instead, you provide the
names and values manually.
check_box_tag
Creates a check box form input tag.
field_set_tag
file_field_tag
form_tag
hidden_field_tag
image_submit_tag
label_tag
password_field_tag
radio_button_tag
select_tag
url_field_tag
date_field_tag
JavaScriptHelper
Provides functionality for working with JavaScript in
your views.
NumberHelper
Provides methods for converting numbers into
formatted strings. Methods are provided for
phone numbers, currency, percentage, precision,
positional notation, and file size.
number_to_currency
number_to_human_size
number_to_percentage
number_to_phone
number_with_delimiter
number_with_precision
Thank you

More Related Content

What's hot

Basic Crud In Django
Basic Crud In DjangoBasic Crud In Django
Basic Crud In Djangomcantelon
 
Android app development lesson 1
Android app development lesson 1Android app development lesson 1
Android app development lesson 1Kalluri Vinay Reddy
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892Tuna Tore
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLAkhil Mittal
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Tuna Tore
 
.NET Core, ASP.NET Core Course, Session 13
.NET Core, ASP.NET Core Course, Session 13.NET Core, ASP.NET Core Course, Session 13
.NET Core, ASP.NET Core Course, Session 13aminmesbahi
 
Drupal8 render pipeline
Drupal8 render pipelineDrupal8 render pipeline
Drupal8 render pipelineMahesh Salaria
 
Using the Features API
Using the Features APIUsing the Features API
Using the Features APIcgmonroe
 
Create an android app for database creation using.pptx
Create an android app for database creation using.pptxCreate an android app for database creation using.pptx
Create an android app for database creation using.pptxvishal choudhary
 
How To Manage API Request with AXIOS on a React Native App
How To Manage API Request with AXIOS on a React Native AppHow To Manage API Request with AXIOS on a React Native App
How To Manage API Request with AXIOS on a React Native AppAndolasoft Inc
 
Create an application with ember
Create an application with ember Create an application with ember
Create an application with ember Chandra Sekar
 
Core Data with Swift 3.0
Core Data with Swift 3.0Core Data with Swift 3.0
Core Data with Swift 3.0Korhan Bircan
 
.NET Core, ASP.NET Core Course, Session 12
.NET Core, ASP.NET Core Course, Session 12.NET Core, ASP.NET Core Course, Session 12
.NET Core, ASP.NET Core Course, Session 12aminmesbahi
 
Html 5, a gentle introduction
Html 5, a gentle introductionHtml 5, a gentle introduction
Html 5, a gentle introductionDiego Scataglini
 
Lab: Developing with the extension library
Lab: Developing with the extension libraryLab: Developing with the extension library
Lab: Developing with the extension libraryWorkFlowStudios
 
Html5, a gentle introduction
Html5, a gentle introduction Html5, a gentle introduction
Html5, a gentle introduction Diego Scataglini
 

What's hot (20)

Basic Crud In Django
Basic Crud In DjangoBasic Crud In Django
Basic Crud In Django
 
Android app development lesson 1
Android app development lesson 1Android app development lesson 1
Android app development lesson 1
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQL
 
The most basic inline tag
The most basic inline tagThe most basic inline tag
The most basic inline tag
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5
 
.NET Core, ASP.NET Core Course, Session 13
.NET Core, ASP.NET Core Course, Session 13.NET Core, ASP.NET Core Course, Session 13
.NET Core, ASP.NET Core Course, Session 13
 
Drupal8 render pipeline
Drupal8 render pipelineDrupal8 render pipeline
Drupal8 render pipeline
 
Using the Features API
Using the Features APIUsing the Features API
Using the Features API
 
Create an android app for database creation using.pptx
Create an android app for database creation using.pptxCreate an android app for database creation using.pptx
Create an android app for database creation using.pptx
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Polymer
PolymerPolymer
Polymer
 
Lab2-android
Lab2-androidLab2-android
Lab2-android
 
How To Manage API Request with AXIOS on a React Native App
How To Manage API Request with AXIOS on a React Native AppHow To Manage API Request with AXIOS on a React Native App
How To Manage API Request with AXIOS on a React Native App
 
Create an application with ember
Create an application with ember Create an application with ember
Create an application with ember
 
Core Data with Swift 3.0
Core Data with Swift 3.0Core Data with Swift 3.0
Core Data with Swift 3.0
 
.NET Core, ASP.NET Core Course, Session 12
.NET Core, ASP.NET Core Course, Session 12.NET Core, ASP.NET Core Course, Session 12
.NET Core, ASP.NET Core Course, Session 12
 
Html 5, a gentle introduction
Html 5, a gentle introductionHtml 5, a gentle introduction
Html 5, a gentle introduction
 
Lab: Developing with the extension library
Lab: Developing with the extension libraryLab: Developing with the extension library
Lab: Developing with the extension library
 
Html5, a gentle introduction
Html5, a gentle introduction Html5, a gentle introduction
Html5, a gentle introduction
 

Viewers also liked

Guía de clase primero bloque 3
Guía de clase primero bloque 3Guía de clase primero bloque 3
Guía de clase primero bloque 3JEDANNIE Apellidos
 
Guía de matemática 3º básico
Guía de matemática 3º básicoGuía de matemática 3º básico
Guía de matemática 3º básicokr3ng
 
Genetically Modified Foods presentation
Genetically Modified Foods presentationGenetically Modified Foods presentation
Genetically Modified Foods presentationGina Peace
 
♪ウォーキング瞑想♪
♪ウォーキング瞑想♪♪ウォーキング瞑想♪
♪ウォーキング瞑想♪Hitoshi Tsuchiyama
 
Verb to be
Verb to beVerb to be
Verb to bekr3ng
 
Prueba historia 3º básico
Prueba historia 3º básicoPrueba historia 3º básico
Prueba historia 3º básicokr3ng
 
Biotecnología alimentos
Biotecnología alimentosBiotecnología alimentos
Biotecnología alimentosiesaverroes
 
Biomedical instrumentation
Biomedical instrumentationBiomedical instrumentation
Biomedical instrumentationTapeshwar Yadav
 

Viewers also liked (13)

Consar 5
Consar 5Consar 5
Consar 5
 
Parsons_resume
Parsons_resumeParsons_resume
Parsons_resume
 
Resume
ResumeResume
Resume
 
Configuration
ConfigurationConfiguration
Configuration
 
Guía de clase primero bloque 3
Guía de clase primero bloque 3Guía de clase primero bloque 3
Guía de clase primero bloque 3
 
Guía de matemática 3º básico
Guía de matemática 3º básicoGuía de matemática 3º básico
Guía de matemática 3º básico
 
Genetically Modified Foods presentation
Genetically Modified Foods presentationGenetically Modified Foods presentation
Genetically Modified Foods presentation
 
♪ウォーキング瞑想♪
♪ウォーキング瞑想♪♪ウォーキング瞑想♪
♪ウォーキング瞑想♪
 
Verb to be
Verb to beVerb to be
Verb to be
 
Carbohidratos
CarbohidratosCarbohidratos
Carbohidratos
 
Prueba historia 3º básico
Prueba historia 3º básicoPrueba historia 3º básico
Prueba historia 3º básico
 
Biotecnología alimentos
Biotecnología alimentosBiotecnología alimentos
Biotecnología alimentos
 
Biomedical instrumentation
Biomedical instrumentationBiomedical instrumentation
Biomedical instrumentation
 

Similar to Actionview

Templates, partials and layouts
Templates, partials and layoutsTemplates, partials and layouts
Templates, partials and layoutsKadiv Vech
 
Useful Rails Plugins
Useful Rails PluginsUseful Rails Plugins
Useful Rails Pluginsnavjeet
 
Architecture Specification - Visual Modeling Tool
Architecture Specification - Visual Modeling ToolArchitecture Specification - Visual Modeling Tool
Architecture Specification - Visual Modeling ToolAdriaan Venter
 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsAlessandro Molina
 
Django 1.10.3 Getting started
Django 1.10.3 Getting startedDjango 1.10.3 Getting started
Django 1.10.3 Getting startedMoniaJ
 
6 introduction-php-mvc-cakephp-m6-views-slides
6 introduction-php-mvc-cakephp-m6-views-slides6 introduction-php-mvc-cakephp-m6-views-slides
6 introduction-php-mvc-cakephp-m6-views-slidesMasterCode.vn
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010vchircu
 
RubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendallRubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendalltutorialsruby
 
AEM Sightly Deep Dive
AEM Sightly Deep DiveAEM Sightly Deep Dive
AEM Sightly Deep DiveGabriel Walt
 
Adding a view
Adding a viewAdding a view
Adding a viewNhan Do
 
Appcelerator Titanium Alloy + Kinvey Collection Databinding - Part One
Appcelerator Titanium Alloy + Kinvey Collection Databinding - Part OneAppcelerator Titanium Alloy + Kinvey Collection Databinding - Part One
Appcelerator Titanium Alloy + Kinvey Collection Databinding - Part OneAaron Saunders
 
Yii in action
Yii in actionYii in action
Yii in actionKeaNy Chu
 
Web Programming - 7 Blading Template
Web Programming - 7 Blading TemplateWeb Programming - 7 Blading Template
Web Programming - 7 Blading TemplateAndiNurkholis1
 

Similar to Actionview (20)

Templates, partials and layouts
Templates, partials and layoutsTemplates, partials and layouts
Templates, partials and layouts
 
Rails review
Rails reviewRails review
Rails review
 
Useful Rails Plugins
Useful Rails PluginsUseful Rails Plugins
Useful Rails Plugins
 
Architecture Specification - Visual Modeling Tool
Architecture Specification - Visual Modeling ToolArchitecture Specification - Visual Modeling Tool
Architecture Specification - Visual Modeling Tool
 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable Applications
 
Django 1.10.3 Getting started
Django 1.10.3 Getting startedDjango 1.10.3 Getting started
Django 1.10.3 Getting started
 
6 introduction-php-mvc-cakephp-m6-views-slides
6 introduction-php-mvc-cakephp-m6-views-slides6 introduction-php-mvc-cakephp-m6-views-slides
6 introduction-php-mvc-cakephp-m6-views-slides
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
 
ASP.NET MVC3 RAD
ASP.NET MVC3 RADASP.NET MVC3 RAD
ASP.NET MVC3 RAD
 
Web technologies part-2
Web technologies part-2Web technologies part-2
Web technologies part-2
 
RubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendallRubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendall
 
AEM Sightly Deep Dive
AEM Sightly Deep DiveAEM Sightly Deep Dive
AEM Sightly Deep Dive
 
Adding a view
Adding a viewAdding a view
Adding a view
 
Intro to OctoberCMS
Intro to OctoberCMSIntro to OctoberCMS
Intro to OctoberCMS
 
Struts 2
Struts 2Struts 2
Struts 2
 
Appcelerator Titanium Alloy + Kinvey Collection Databinding - Part One
Appcelerator Titanium Alloy + Kinvey Collection Databinding - Part OneAppcelerator Titanium Alloy + Kinvey Collection Databinding - Part One
Appcelerator Titanium Alloy + Kinvey Collection Databinding - Part One
 
Yii in action
Yii in actionYii in action
Yii in action
 
Web Programming - 7 Blading Template
Web Programming - 7 Blading TemplateWeb Programming - 7 Blading Template
Web Programming - 7 Blading Template
 
Unit 2 - Data Binding.pptx
Unit 2 - Data Binding.pptxUnit 2 - Data Binding.pptx
Unit 2 - Data Binding.pptx
 
ReactJS.pptx
ReactJS.pptxReactJS.pptx
ReactJS.pptx
 

Recently uploaded

What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 

Recently uploaded (20)

What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 

Actionview

  • 2. What is Action View? Action View and Action Controller are the two major components of Action Pack.  In Rails, web requests are handled by Action Pack, which splits the work into a controller part (performing the logic) and a view part (rendering a template).  Typically, Action Controller will be concerned with communicating with the database and
  • 3. Using Action View with Rails For each controller there is an associated directory in the app/views directory which holds the template files that make up the views associated with that controller. These files are used to display the view that results from each controller action.
  • 4. Example of view in scaffold generator : $ bin/rails generate scaffold article  [...]  invoke scaffold_controller  create app/controllers/articles_controller.r b  invoke erb  create app/views/articles
  • 5. There is a naming convention for views in Rails. Typically, the views share their name with the associated controller action, as you can see above. For example, the index controller action of the articles_controller.rb will use the index.html.erb view file in the app/views/articles directory. The complete HTML returned to the client is composed of a combination of this ERB file, a layout template that wraps it, and all the partials that the view may reference
  • 6. Templates, Partials and Layouts Templates Action View templates can be written in several ways. If the template file has a .erb extension then it uses a mixture of ERB (Embedded Ruby) and HTML. If the template file has a .builder extension then the Builder::XmlMarkup library is used.
  • 7. ERB Within an ERB template, Ruby code can be included using both <% %> and <%= %> tags. The <% %> tags are used to execute Ruby code that does not return anything, such as conditions, loops or blocks, and the <%= %> tags are used when you want output. Consider the following loop for names:
  • 8. 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")
  • 9. Partials Partial templates - usually just called "partials" - are another device for breaking the rendering process into more manageable chunks. With partials, you can extract pieces of code from your templates to separate files and also reuse them throughout your templates.
  • 10. Naming Partials To render a partial as part of a view, you use the render method within the view: <%= render "menu" %> This will render a file named _menu.html.erb at that point within the view that is being rendered. Note the leading underscore character: partials are named with a leading underscore to distinguish them from regular views, even though they are referred to without the underscore. This holds true even when you're pulling in a partial from another
  • 11. Layouts Layouts can be used to render a common view template around the results of Rails controller actions. Typically, a Rails application will have a couple of layouts that pages will be rendered within.  For example, a site might have one layout for a logged in user and another for the marketing or sales side of the site.
  • 12. Partial Layouts Partials can have their own layouts applied to them. These layouts are different from those applied to a controller action, but they work in a similar fashion. Let's say we're displaying an article on a page which should be wrapped in a div for display purposes. Firstly, we'll create a new Article: Article.create(body: 'Partial Layouts are cool!') In the show template, we'll render the _article partial wrapped in the box layout:
  • 13. articles/_box.html.erb <div class='box'> <%= yield %> </div> The _article partial wraps the article's body in a div with the id of the article using the div_for helper:
  • 14. this would output the following: <div class='box'> <div id='article_1'> <p>Partial Layouts are cool!</p> </div> </div>
  • 15. Overview of helpers provided by Action View  RecordTagHelper This module provides methods for generating container tags, such as div, for your record. This is the recommended way of creating a container for render your Active Record object, as it adds an appropriate class and id attributes to that container. You can then refer to those containers easily by following the
  • 16. content_tag_for Renders a container tag that relates to your Active Record Object. For example, given @article is the object of Article class, you can do: <%= content_tag_for(:tr, @article) do %>
  • 17. This will generate this HTML output: <tr id="article_1234" class="article"> <td>Hello World!</td> </tr>
  • 18. div_for This is actually a convenient method which calls content_tag_for internally with :div as the tag name. You can pass either an Active Record object or a collection of objects. For example: <%= div_for(@article, class: "frontpage") do %>
  • 19. AssetTagHelper This module provides methods for generating HTML that links views to assets such as images, JavaScript files, stylesheets, and feeds. By default, Rails links to these assets on the current host in the public folder, but you can direct Rails to link to assets from a dedicated assets server by setting config.action_controller.asset_host in the
  • 20. register_javascript_expansion Register one or more JavaScript files to be included when symbol is passed to javascript_include_tag. This method is typically intended to be called from plugin initialization to register JavaScript files that the plugin installed in vendor/assets/javascripts. ActionView::Helpers::AssetTagHelper.regist
  • 21. register_stylesheet_expansion Register one or more stylesheet files to be included when symbol is passed to stylesheet_link_tag. This method is typically intended to be called from plugin initialization to register stylesheet files that the plugin installed in vendor/assets/stylesheets. ActionView::Helpers::AssetTagHelper.register _stylesheet_expansion monkey: ["head",
  • 22. auto_discovery_link_tag Returns a link tag that browsers and feed readers can use to auto-detect an RSS or Atom feed. auto_discovery_link_tag(:rss, "http://www.example.com/feed.rss", {title: "RSS Feed"}) # => <link rel="alternate"
  • 23. Image_path Computes the path to an image asset in the app/assets/images directory. Full paths from the document root will be passed through. Used internally by image_tag to build the image path. image_path("edit.png") # => /assets/edit.png
  • 24. image_url Computes the url to an image asset in the app/assets/images directory. This will call image_path internally and merge with your current host or your asset host. image_url("edit.png") # => http://www.example.com/assets/edit.png
  • 25. javascript_include_tag Returns an HTML script tag for each of the sources provided. You can pass in the filename (.js extension is optional) of JavaScript files that exist in your app/assets/javascripts directory for inclusion into the current page or you can pass the full path relative to your document root. javascript_include_tag "common" # => <script src="/assets/common.js"></script>
  • 26. javascript_path Computes the path to a JavaScript asset in the app/assets/javascripts directory. If the source filename has no extension, .js will be appended. Full paths from the document root will be passed through. Used internally by javascript_include_tag to build the script path.
  • 27. stylesheet_link_tag Returns a stylesheet link tag for the sources specified as arguments. If you don't specify an extension, .css will be appended automatically. stylesheet_link_tag "application" # => <link href="/assets/application.css" media="screen" rel="stylesheet" />
  • 28. stylesheet_path Computes the path to a stylesheet asset in the app/assets/stylesheets directory. If the source filename has no extension, .css will be appended. Full paths from the document root will be passed through. Used internally by stylesheet_link_tag to build the stylesheet path. stylesheet_path "application" # => /assets/application.css
  • 29. DateHelper date_select Returns a set of select tags (one for year, month, and day) pre-selected for accessing a specified date-based attribute. date_select("article", "published_on") datetime_select Returns a set of select tags (one for year, month, day, hour, and minute) pre- selected for accessing a specified
  • 30. distance_of_time_in_words Reports the approximate distance in time between two Time or Date objects or integers as seconds. Set include_seconds to true if you want more detailed approximations. distance_of_time_in_words(Time.now, Time.now + 15.seconds) # => less than a minute distance_of_time_in_words(Time.now, Time.now + 15.seconds, include_seconds: true) # => less than 20 seconds
  • 31. select_datetime Returns a set of HTML select-tags (one for year, month, day, hour, and minute) pre-selected with the datetime provided. # Generates a datetime select that defaults to the datetime provided (four days after today) select_datetime(Time.now + 4.days) # Generates a datetime select that defaults to today (no specified datetime)
  • 33. FormHelper Form helpers are designed to make working with models much easier compared to using just standard HTML elements by providing a set of methods for creating forms based on your models. This helper generates the HTML for forms, providing a method for each sort of input (e.g., text, password, select, and so on).
  • 34. form_for, gives you the ability to create a form for a model instance; for example, let's say that you have a model Person and want to create a new instance of it: <%= form_for @person, url: {action: "create"} do |f| %> <%= f.text_field :first_name %> <%= f.text_field :last_name %> <%= submit_tag 'Create' %> <% end %> The HTML generated for this would be:
  • 35. The params object created when this form is submitted would look like: {"action" => "create", "controller" => "people", "person" => {"first_name" => "William", "last_name" => "Smith"}} Check_box Returns a checkbox tag tailored for accessing a specified attribute.
  • 36. file_field Returns a file upload input tag tailored for accessing a specified attribute. file_field(:user, :avatar) # => <input type="file" id="user_avatar" name="user[avatar]" /> form_for Creates a form and a scope around a specific model object that is used as a base for questioning about values for the fields.
  • 37. hidden_field Returns a hidden input tag tailored for accessing a specified attribute. hidden_field(:user, :token) # => <input type="hidden" id="user_token" name="user[token]" value="#{@user.token}" /> label Returns a label tag tailored for labelling an
  • 38. password_field Returns an input tag of the "password" type tailored for accessing a specified attribute. password_field(:login, :pass) # => <input type="text" id="login_pass" name="login[pass]" value="#{@login.pass}" /> radio_button Returns a radio button tag for accessing a specified attribute.
  • 39. text_field Returns an input tag of the "text" type tailored for accessing a specified attribute. text_field(:article, :title) # => <input type="text" id="article_title" name="article[title]" value="#{@article.title}" /> email_field Returns an input tag of the "email" type tailored for accessing a specified attribute.
  • 40. url_field Returns an input tag of the "url" type tailored for accessing a specified attribute. url_field(:user, :url) # => <input type="url" id="user_url" name="user[url]" value="#{@user.url}" /> FormOptionsHelper Provides a number of methods for turning different kinds of containers into a set of option tags.
  • 41. Example object structure for use with this method: class Article < ActiveRecord::Base belongs_to :author end class Author < ActiveRecord::Base has_many :articles
  • 43. Select Create a select tag and a series of contained option tags for the provided object and method. Example: select("article", "person_id", Person.all.collect {|p| [ p.name, p.id ] }, {include_blank: true}) If @article.person_id is 1, this would become:
  • 44. 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 time_zone_options_for_select to generate the list of option tags. time_zone_select( "user", "time_zone")
  • 45. FormTagHelper Provides a number of methods for creating form tags that don't rely on an Active Record object assigned to the template like FormHelper does. Instead, you provide the names and values manually. check_box_tag Creates a check box form input tag.
  • 48. JavaScriptHelper Provides functionality for working with JavaScript in your views. NumberHelper Provides methods for converting numbers into formatted strings. Methods are provided for phone numbers, currency, percentage, precision, positional notation, and file size.