SlideShare a Scribd company logo
Understanding Form Helpers
Bruno Almeida
● Form tag
● Form to an object
● Select
● Customize fields
● Nested forms
Let’s begin
Form tag
http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html
form_tag
<%= form_tag do %>
Form contents
<% end %>
<form action="/" accept-charset="UTF-8" method="post">
<input name="utf8" type="hidden" value="&#x2713;" />
<input type="hidden" name="authenticity_token" value="
jzi1o/1Wl8yTZ2e1Z3QE99BFYI5uouuaFa/HdyyOJP9knHGBMpiGjuNlDP
VhctUX2/qQsFUxCaChV7JSgm0Mnw==" />
Form contents
</form>
label_tag, text_field_tag, submit_tag
<%= form_tag("/search", method: "get") do %>
<%= label_tag(:q, "Search for:") %>
<%= text_field_tag(:q) %>
<%= submit_tag("Search") %>
<% end %>
<form accept-charset="UTF-8" action="/search" method="get">
<input name="utf8" type="hidden" value="&#x2713;" />
<label for="q">Search for:</label>
<input id="q" name="q" type="text" />
<input name="commit" type="submit" value="Search" />
</form>
Others input helpers
<%= password_field_tag(:password) %>
<%= hidden_field_tag(:parent_id, "5") %>
<%= number_field(:product, :price, in:
1.0..20.0, step: 0.5) %>
<input type="password" name="password" id="password" />
<input type="hidden" name="parent_id" id="parent_id"
value="5" />
<input step="0.5" min="1.0" max="20.0" type="number"
name="product[price]" id="product_price" />
search_field, telephone_field, date_field, datetime_field, datetime_local_field, month_field,
week_field, url_field, email_field, color_field, time_field, range_field
Form to an object
http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html
Setting up a form to an object
# routes
resources :developers
# controller
def new
@developer = Developer.new
end
# view
<%= form_for @developer do |f| %>
<%= f.text_field :name %><br>
<%= f.text_area :resume %><br>
<%= f.submit %>
<% end %>
<form class="new_developer" id="new_developer" action="/developers"
accept-charset="UTF-8" method="post">
<!-- autenticity_token and utf8 -->
<input type="text" name="developer[name]" id="developer_name" /><br>
<textarea name="developer[resume]" id="developer_resume">
</textarea><br>
<input type="submit" name="commit" value="Create Developer" />
</form>
Label
<%= f.label :name %><br>
<%= f.text_field :name %>
<label for="developer_name">Name</label><br>
<input type="text" name="developer[name]" id="developer_name" />
Error messages
# model
class Developer < ActiveRecord::Base
validates_presence_of :name
end
# view
<% if @developer.errors.any? %>
<ul>
<% @developer.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
<% end %>
<ul>
<li>Name can't be blank</li>
</ul>
Select
http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html
Select with array
<%= f.select(:gender, { M: 1, F: 2 },
{ include_blank: 'Choice' }) %>
<select name="developer[gender]" id="developer_gender">
<option value="">Choice</option>
<option selected="selected" value="1">M</option>
<option value="2">F</option>
</select>
<select name="developer[gender]" id="developer_gender">
<option selected="selected" value="1">M</option>
<option value="2">F</option>
</select>
<%= f.select(:gender, M: 1, F: 2) %>
Select with collection
<%= f.collection_select(:indication_id,
Developer.all, :id, :name,
{ prompt: 'None' }) %>
<select name="developer[indication_id]" id="
developer_indication_id">
<option value="">None</option>
<option value="1">Linus</option>
<option value="2">Bruno</option>
</select>
<select name="developer[indication_id]" id="
developer_indication_id">
<option value="1">Linus</option>
<option value="2">Bruno</option>
</select>
<%= f.collection_select(:indication_id,
Developer.all, :id, :name) %>
Customize fields
Select
<%= f.select(
:gender,
{ M: 1, F: 2 },
{ include_blank: 'Choice' },
{
class: 'css-class',
data: { id: 'gender', optional: true }
}
) %>
<select class="css-class" data-id="gender" data-
optional="true" name="developer[gender]" id="
developer_gender">
Nested forms
http://guides.rubyonrails.org/form_helpers.html#nested-forms
Configure model and controller
# controller
class DevelopersController < ApplicationController
def new
@developer = Developer.new
@developer.addresses.build
end
def developer_params
params.require(:developer).permit(:name, :resume, :
gender,
addresses_attributes: [:id, :name, :street])
end
end
# models
class Address < ActiveRecord::Base
belongs_to :developer
end
class Developer < ActiveRecord::Base
has_many :addresses
accepts_nested_attributes_for :addresses
end
Add nested form to view…
<%= form_for @developer do |f| %>
...
<%= f.fields_for :addresses do |addresses_form| %>
<%= addresses_form.text_field :name %>
<%= addresses_form.text_field :street %>
<% end %>
...
<% end %>
… renders
<input type="text" value="" name="developer[addresses_attributes][0][name]" id="
developer_addresses_attributes_0_name" />
<input type="text" value="" name="developer[addresses_attributes][0][street]" id="
developer_addresses_attributes_0_street" />
<input type="hidden" value="1" name="developer[addresses_attributes][0][id]" id="
developer_addresses_attributes_0_id" />
That's all folks
Bruno Almeida
https://github.com/wwwbruno
https://facebook.com/wwwbruno
https://twitter.com/@wwwbruno
http://www.slideshare.net/wwwbruno
Any questions?

More Related Content

What's hot

Https set up
Https set upHttps set up
Https set up
<svg> \">
 
Decompiladores
DecompiladoresDecompiladores
Decompiladores
Jhon Alexito
 
Static Reference Analysis for GUI Objects in Android Software
Static Reference Analysis for GUI Objects in Android SoftwareStatic Reference Analysis for GUI Objects in Android Software
Static Reference Analysis for GUI Objects in Android Software
Dacong (Tony) Yan
 
Introduction to UI Components in Magento 2
Introduction to UI Components in Magento 2Introduction to UI Components in Magento 2
Introduction to UI Components in Magento 2
Sergii Ivashchenko
 
Magento 2 UI Components Overview
Magento 2 UI Components OverviewMagento 2 UI Components Overview
Magento 2 UI Components Overview
eGlobe IT Solutions
 
Modules and injector
Modules and injectorModules and injector
Modules and injector
Eyal Vardi
 
23. CodeIgniter sessions
23. CodeIgniter sessions23. CodeIgniter sessions
23. CodeIgniter sessions
Razvan Raducanu, PhD
 
Security in laravel
Security in laravelSecurity in laravel
Security in laravel
Sayed Ahmed
 
Binary Studio Academy 2016: Laravel Controllers
Binary Studio Academy 2016: Laravel ControllersBinary Studio Academy 2016: Laravel Controllers
Binary Studio Academy 2016: Laravel Controllers
Binary Studio
 
Confluence - Improving Space Navigation. London AUG October 2013
Confluence - Improving Space Navigation. London AUG October 2013Confluence - Improving Space Navigation. London AUG October 2013
Confluence - Improving Space Navigation. London AUG October 2013
Charles_Hall
 
Support Design Library
Support Design LibrarySupport Design Library
Support Design Library
Grigoriy Dzhanelidze
 
Droidcon Moscow 2015. Support Design Library. Григорий Джанелидзе - e-Legion
Droidcon Moscow 2015. Support Design Library. Григорий Джанелидзе - e-LegionDroidcon Moscow 2015. Support Design Library. Григорий Джанелидзе - e-Legion
Droidcon Moscow 2015. Support Design Library. Григорий Джанелидзе - e-Legion
Mail.ru Group
 
AngularJs - Part 3
AngularJs - Part 3AngularJs - Part 3
AngularJs - Part 3
Nishikant Taksande
 
5. hello popescu
5. hello popescu5. hello popescu
5. hello popescu
Razvan Raducanu, PhD
 
날로 먹는 Django admin 활용
날로 먹는 Django admin 활용날로 먹는 Django admin 활용
날로 먹는 Django admin 활용
KyeongMook "Kay" Cha
 
jQuery 實戰經驗講座
jQuery 實戰經驗講座jQuery 實戰經驗講座
jQuery 實戰經驗講座
Jace Ju
 
Laravel 로 배우는 서버사이드 #5
Laravel 로 배우는 서버사이드 #5Laravel 로 배우는 서버사이드 #5
Laravel 로 배우는 서버사이드 #5
성일 한
 
Building scalable products with WordPress - WordCamp London 2018
Building scalable products with WordPress - WordCamp London 2018Building scalable products with WordPress - WordCamp London 2018
Building scalable products with WordPress - WordCamp London 2018
Elliot Taylor
 
Lo nuevo de Django 1.7 y 1.8
Lo nuevo de Django 1.7 y 1.8Lo nuevo de Django 1.7 y 1.8
Lo nuevo de Django 1.7 y 1.8
pedroburonv
 
Stole16
Stole16Stole16
Stole16
rworldoffice
 

What's hot (20)

Https set up
Https set upHttps set up
Https set up
 
Decompiladores
DecompiladoresDecompiladores
Decompiladores
 
Static Reference Analysis for GUI Objects in Android Software
Static Reference Analysis for GUI Objects in Android SoftwareStatic Reference Analysis for GUI Objects in Android Software
Static Reference Analysis for GUI Objects in Android Software
 
Introduction to UI Components in Magento 2
Introduction to UI Components in Magento 2Introduction to UI Components in Magento 2
Introduction to UI Components in Magento 2
 
Magento 2 UI Components Overview
Magento 2 UI Components OverviewMagento 2 UI Components Overview
Magento 2 UI Components Overview
 
Modules and injector
Modules and injectorModules and injector
Modules and injector
 
23. CodeIgniter sessions
23. CodeIgniter sessions23. CodeIgniter sessions
23. CodeIgniter sessions
 
Security in laravel
Security in laravelSecurity in laravel
Security in laravel
 
Binary Studio Academy 2016: Laravel Controllers
Binary Studio Academy 2016: Laravel ControllersBinary Studio Academy 2016: Laravel Controllers
Binary Studio Academy 2016: Laravel Controllers
 
Confluence - Improving Space Navigation. London AUG October 2013
Confluence - Improving Space Navigation. London AUG October 2013Confluence - Improving Space Navigation. London AUG October 2013
Confluence - Improving Space Navigation. London AUG October 2013
 
Support Design Library
Support Design LibrarySupport Design Library
Support Design Library
 
Droidcon Moscow 2015. Support Design Library. Григорий Джанелидзе - e-Legion
Droidcon Moscow 2015. Support Design Library. Григорий Джанелидзе - e-LegionDroidcon Moscow 2015. Support Design Library. Григорий Джанелидзе - e-Legion
Droidcon Moscow 2015. Support Design Library. Григорий Джанелидзе - e-Legion
 
AngularJs - Part 3
AngularJs - Part 3AngularJs - Part 3
AngularJs - Part 3
 
5. hello popescu
5. hello popescu5. hello popescu
5. hello popescu
 
날로 먹는 Django admin 활용
날로 먹는 Django admin 활용날로 먹는 Django admin 활용
날로 먹는 Django admin 활용
 
jQuery 實戰經驗講座
jQuery 實戰經驗講座jQuery 實戰經驗講座
jQuery 實戰經驗講座
 
Laravel 로 배우는 서버사이드 #5
Laravel 로 배우는 서버사이드 #5Laravel 로 배우는 서버사이드 #5
Laravel 로 배우는 서버사이드 #5
 
Building scalable products with WordPress - WordCamp London 2018
Building scalable products with WordPress - WordCamp London 2018Building scalable products with WordPress - WordCamp London 2018
Building scalable products with WordPress - WordCamp London 2018
 
Lo nuevo de Django 1.7 y 1.8
Lo nuevo de Django 1.7 y 1.8Lo nuevo de Django 1.7 y 1.8
Lo nuevo de Django 1.7 y 1.8
 
Stole16
Stole16Stole16
Stole16
 

Viewers also liked

Brincando com FFI no Ruby
Brincando com FFI no RubyBrincando com FFI no Ruby
Brincando com FFI no Ruby
Weverton Timoteo
 
Git - Workshop Disruptiva
Git - Workshop DisruptivaGit - Workshop Disruptiva
Git - Workshop Disruptiva
Bruno Almeida
 
RubyMotion: Put your Dreams in Motion with Ruby
RubyMotion: Put your Dreams in Motion with RubyRubyMotion: Put your Dreams in Motion with Ruby
RubyMotion: Put your Dreams in Motion with Ruby
Astrails
 
Concurrency in Ruby
Concurrency in RubyConcurrency in Ruby
Concurrency in Ruby
Jônatas Paganini
 
ניטור ומחקר וידיאו באינטרנט
ניטור ומחקר וידיאו באינטרנטניטור ומחקר וידיאו באינטרנט
ניטור ומחקר וידיאו באינטרנט
IFAT GROUP
 
Ad Design - Galaxy Gala
Ad Design - Galaxy GalaAd Design - Galaxy Gala
Ad Design - Galaxy Gala
Nancy Batchelor
 
Mir datasheet
Mir datasheetMir datasheet
Mir datasheet
Quantum Composers
 
3
33
Iсторичнi аспекти соцiалiзацii...
Iсторичнi аспекти соцiалiзацii...Iсторичнi аспекти соцiалiзацii...
Iсторичнi аспекти соцiалiзацii...
Nataliya Pazina
 
Austcoast
AustcoastAustcoast
чуло вида
чуло видачуло вида
чуло вида
Maja Simic
 
Ons Wadden Gebied
Ons Wadden GebiedOns Wadden Gebied
Ons Wadden Gebied
Steven Roberts
 
Ioug oow12 em12c
Ioug oow12 em12cIoug oow12 em12c
Ioug oow12 em12c
Kellyn Pot'Vin-Gorman
 
การประเมินการอ่าน คิดวิเคราะห์ และเขียน
การประเมินการอ่าน คิดวิเคราะห์ และเขียนการประเมินการอ่าน คิดวิเคราะห์ และเขียน
การประเมินการอ่าน คิดวิเคราะห์ และเขียนkrupornpana55
 
Trabajo unidad 3
Trabajo unidad 3Trabajo unidad 3
Trabajo unidad 3
Mateo Ortiz
 
Where is Wally - user study af Bettina Ridler og Helle Mortensen, GN Netcom
Where is Wally - user study af Bettina Ridler og Helle Mortensen, GN NetcomWhere is Wally - user study af Bettina Ridler og Helle Mortensen, GN Netcom
Where is Wally - user study af Bettina Ridler og Helle Mortensen, GN Netcom
InfinIT - Innovationsnetværket for it
 
Ch 1 organization of construction projects
Ch 1 organization of construction projectsCh 1 organization of construction projects
Ch 1 organization of construction projects
Tu Nguyen, PMP®,PMI-RMP®
 
Automatiseret GUI-test af Lars Kjølholm, BRF Kredit
Automatiseret GUI-test af Lars Kjølholm, BRF KreditAutomatiseret GUI-test af Lars Kjølholm, BRF Kredit
Automatiseret GUI-test af Lars Kjølholm, BRF Kredit
InfinIT - Innovationsnetværket for it
 
Portable network graphics
Portable network graphicsPortable network graphics
Portable network graphics
Esty Swandana
 

Viewers also liked (19)

Brincando com FFI no Ruby
Brincando com FFI no RubyBrincando com FFI no Ruby
Brincando com FFI no Ruby
 
Git - Workshop Disruptiva
Git - Workshop DisruptivaGit - Workshop Disruptiva
Git - Workshop Disruptiva
 
RubyMotion: Put your Dreams in Motion with Ruby
RubyMotion: Put your Dreams in Motion with RubyRubyMotion: Put your Dreams in Motion with Ruby
RubyMotion: Put your Dreams in Motion with Ruby
 
Concurrency in Ruby
Concurrency in RubyConcurrency in Ruby
Concurrency in Ruby
 
ניטור ומחקר וידיאו באינטרנט
ניטור ומחקר וידיאו באינטרנטניטור ומחקר וידיאו באינטרנט
ניטור ומחקר וידיאו באינטרנט
 
Ad Design - Galaxy Gala
Ad Design - Galaxy GalaAd Design - Galaxy Gala
Ad Design - Galaxy Gala
 
Mir datasheet
Mir datasheetMir datasheet
Mir datasheet
 
3
33
3
 
Iсторичнi аспекти соцiалiзацii...
Iсторичнi аспекти соцiалiзацii...Iсторичнi аспекти соцiалiзацii...
Iсторичнi аспекти соцiалiзацii...
 
Austcoast
AustcoastAustcoast
Austcoast
 
чуло вида
чуло видачуло вида
чуло вида
 
Ons Wadden Gebied
Ons Wadden GebiedOns Wadden Gebied
Ons Wadden Gebied
 
Ioug oow12 em12c
Ioug oow12 em12cIoug oow12 em12c
Ioug oow12 em12c
 
การประเมินการอ่าน คิดวิเคราะห์ และเขียน
การประเมินการอ่าน คิดวิเคราะห์ และเขียนการประเมินการอ่าน คิดวิเคราะห์ และเขียน
การประเมินการอ่าน คิดวิเคราะห์ และเขียน
 
Trabajo unidad 3
Trabajo unidad 3Trabajo unidad 3
Trabajo unidad 3
 
Where is Wally - user study af Bettina Ridler og Helle Mortensen, GN Netcom
Where is Wally - user study af Bettina Ridler og Helle Mortensen, GN NetcomWhere is Wally - user study af Bettina Ridler og Helle Mortensen, GN Netcom
Where is Wally - user study af Bettina Ridler og Helle Mortensen, GN Netcom
 
Ch 1 organization of construction projects
Ch 1 organization of construction projectsCh 1 organization of construction projects
Ch 1 organization of construction projects
 
Automatiseret GUI-test af Lars Kjølholm, BRF Kredit
Automatiseret GUI-test af Lars Kjølholm, BRF KreditAutomatiseret GUI-test af Lars Kjølholm, BRF Kredit
Automatiseret GUI-test af Lars Kjølholm, BRF Kredit
 
Portable network graphics
Portable network graphicsPortable network graphics
Portable network graphics
 

Similar to Understanding form helpers

Action View Form Helpers - 1, Season 2
Action View Form Helpers - 1, Season 2Action View Form Helpers - 1, Season 2
Action View Form Helpers - 1, Season 2
RORLAB
 
Action View Form Helpers - 2, Season 2
Action View Form Helpers - 2, Season 2Action View Form Helpers - 2, Season 2
Action View Form Helpers - 2, Season 2
RORLAB
 
Intro to Jinja2 Templates - San Francisco Flask Meetup
Intro to Jinja2 Templates - San Francisco Flask MeetupIntro to Jinja2 Templates - San Francisco Flask Meetup
Intro to Jinja2 Templates - San Francisco Flask Meetup
Alan Hamlett
 
How to Create A Magento Adminhtml Controller in Magento Extension
How to Create A Magento Adminhtml Controller in Magento ExtensionHow to Create A Magento Adminhtml Controller in Magento Extension
How to Create A Magento Adminhtml Controller in Magento Extension
Hendy Irawan
 
04 Html Form Get Post Login System
04 Html Form Get Post Login System04 Html Form Get Post Login System
04 Html Form Get Post Login System
Geshan Manandhar
 
jQuery Mobile Introduction ( demo on EZoapp )
jQuery Mobile Introduction ( demo on EZoapp )jQuery Mobile Introduction ( demo on EZoapp )
jQuery Mobile Introduction ( demo on EZoapp )
EZoApp
 
Jinja2 Templates - San Francisco Flask Meetup
Jinja2 Templates - San Francisco Flask MeetupJinja2 Templates - San Francisco Flask Meetup
Jinja2 Templates - San Francisco Flask Meetup
Alan Hamlett
 
Nagios Conference 2014 - Troy Lea - JavaScript and jQuery - Nagios XI Tips, T...
Nagios Conference 2014 - Troy Lea - JavaScript and jQuery - Nagios XI Tips, T...Nagios Conference 2014 - Troy Lea - JavaScript and jQuery - Nagios XI Tips, T...
Nagios Conference 2014 - Troy Lea - JavaScript and jQuery - Nagios XI Tips, T...
Nagios
 
QCon 2015 - Thinking in components: A new paradigm for Web UI
QCon 2015 - Thinking in components: A new paradigm for Web UIQCon 2015 - Thinking in components: A new paradigm for Web UI
QCon 2015 - Thinking in components: A new paradigm for Web UI
Oliver Häger
 
Desenvolvimento web com Ruby on Rails (parte 4)
Desenvolvimento web com Ruby on Rails (parte 4)Desenvolvimento web com Ruby on Rails (parte 4)
Desenvolvimento web com Ruby on Rails (parte 4)
Joao Lucas Santana
 
How to create a magento controller in magento extension
How to create a magento controller in magento extensionHow to create a magento controller in magento extension
How to create a magento controller in magento extension
Hendy Irawan
 
Alfredo-PUMEX
Alfredo-PUMEXAlfredo-PUMEX
Alfredo-PUMEX
tutorialsruby
 
Alfredo-PUMEX
Alfredo-PUMEXAlfredo-PUMEX
Alfredo-PUMEX
tutorialsruby
 
Alfredo-PUMEX
Alfredo-PUMEXAlfredo-PUMEX
Alfredo-PUMEX
tutorialsruby
 
Alfredo-PUMEX
Alfredo-PUMEXAlfredo-PUMEX
Alfredo-PUMEX
tutorialsruby
 
Getting started with Rails (4), Season 2
Getting started with Rails (4), Season 2Getting started with Rails (4), Season 2
Getting started with Rails (4), Season 2
RORLAB
 
Open Selector
Open SelectorOpen Selector
Open Selector
jjdelc
 
HTML::FormFu talk for Sydney PM
HTML::FormFu talk for Sydney PMHTML::FormFu talk for Sydney PM
HTML::FormFu talk for Sydney PM
Dean Hamstead
 
Private slideshow
Private slideshowPrivate slideshow
Private slideshow
sblackman
 
Pengenalan AngularJS
Pengenalan AngularJSPengenalan AngularJS
Pengenalan AngularJS
Edi Santoso
 

Similar to Understanding form helpers (20)

Action View Form Helpers - 1, Season 2
Action View Form Helpers - 1, Season 2Action View Form Helpers - 1, Season 2
Action View Form Helpers - 1, Season 2
 
Action View Form Helpers - 2, Season 2
Action View Form Helpers - 2, Season 2Action View Form Helpers - 2, Season 2
Action View Form Helpers - 2, Season 2
 
Intro to Jinja2 Templates - San Francisco Flask Meetup
Intro to Jinja2 Templates - San Francisco Flask MeetupIntro to Jinja2 Templates - San Francisco Flask Meetup
Intro to Jinja2 Templates - San Francisco Flask Meetup
 
How to Create A Magento Adminhtml Controller in Magento Extension
How to Create A Magento Adminhtml Controller in Magento ExtensionHow to Create A Magento Adminhtml Controller in Magento Extension
How to Create A Magento Adminhtml Controller in Magento Extension
 
04 Html Form Get Post Login System
04 Html Form Get Post Login System04 Html Form Get Post Login System
04 Html Form Get Post Login System
 
jQuery Mobile Introduction ( demo on EZoapp )
jQuery Mobile Introduction ( demo on EZoapp )jQuery Mobile Introduction ( demo on EZoapp )
jQuery Mobile Introduction ( demo on EZoapp )
 
Jinja2 Templates - San Francisco Flask Meetup
Jinja2 Templates - San Francisco Flask MeetupJinja2 Templates - San Francisco Flask Meetup
Jinja2 Templates - San Francisco Flask Meetup
 
Nagios Conference 2014 - Troy Lea - JavaScript and jQuery - Nagios XI Tips, T...
Nagios Conference 2014 - Troy Lea - JavaScript and jQuery - Nagios XI Tips, T...Nagios Conference 2014 - Troy Lea - JavaScript and jQuery - Nagios XI Tips, T...
Nagios Conference 2014 - Troy Lea - JavaScript and jQuery - Nagios XI Tips, T...
 
QCon 2015 - Thinking in components: A new paradigm for Web UI
QCon 2015 - Thinking in components: A new paradigm for Web UIQCon 2015 - Thinking in components: A new paradigm for Web UI
QCon 2015 - Thinking in components: A new paradigm for Web UI
 
Desenvolvimento web com Ruby on Rails (parte 4)
Desenvolvimento web com Ruby on Rails (parte 4)Desenvolvimento web com Ruby on Rails (parte 4)
Desenvolvimento web com Ruby on Rails (parte 4)
 
How to create a magento controller in magento extension
How to create a magento controller in magento extensionHow to create a magento controller in magento extension
How to create a magento controller in magento extension
 
Alfredo-PUMEX
Alfredo-PUMEXAlfredo-PUMEX
Alfredo-PUMEX
 
Alfredo-PUMEX
Alfredo-PUMEXAlfredo-PUMEX
Alfredo-PUMEX
 
Alfredo-PUMEX
Alfredo-PUMEXAlfredo-PUMEX
Alfredo-PUMEX
 
Alfredo-PUMEX
Alfredo-PUMEXAlfredo-PUMEX
Alfredo-PUMEX
 
Getting started with Rails (4), Season 2
Getting started with Rails (4), Season 2Getting started with Rails (4), Season 2
Getting started with Rails (4), Season 2
 
Open Selector
Open SelectorOpen Selector
Open Selector
 
HTML::FormFu talk for Sydney PM
HTML::FormFu talk for Sydney PMHTML::FormFu talk for Sydney PM
HTML::FormFu talk for Sydney PM
 
Private slideshow
Private slideshowPrivate slideshow
Private slideshow
 
Pengenalan AngularJS
Pengenalan AngularJSPengenalan AngularJS
Pengenalan AngularJS
 

Recently uploaded

How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 

Recently uploaded (20)

How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 

Understanding form helpers

  • 2. ● Form tag ● Form to an object ● Select ● Customize fields ● Nested forms
  • 5. form_tag <%= form_tag do %> Form contents <% end %> <form action="/" accept-charset="UTF-8" method="post"> <input name="utf8" type="hidden" value="&#x2713;" /> <input type="hidden" name="authenticity_token" value=" jzi1o/1Wl8yTZ2e1Z3QE99BFYI5uouuaFa/HdyyOJP9knHGBMpiGjuNlDP VhctUX2/qQsFUxCaChV7JSgm0Mnw==" /> Form contents </form>
  • 6. label_tag, text_field_tag, submit_tag <%= form_tag("/search", method: "get") do %> <%= label_tag(:q, "Search for:") %> <%= text_field_tag(:q) %> <%= submit_tag("Search") %> <% end %> <form accept-charset="UTF-8" action="/search" method="get"> <input name="utf8" type="hidden" value="&#x2713;" /> <label for="q">Search for:</label> <input id="q" name="q" type="text" /> <input name="commit" type="submit" value="Search" /> </form>
  • 7. Others input helpers <%= password_field_tag(:password) %> <%= hidden_field_tag(:parent_id, "5") %> <%= number_field(:product, :price, in: 1.0..20.0, step: 0.5) %> <input type="password" name="password" id="password" /> <input type="hidden" name="parent_id" id="parent_id" value="5" /> <input step="0.5" min="1.0" max="20.0" type="number" name="product[price]" id="product_price" /> search_field, telephone_field, date_field, datetime_field, datetime_local_field, month_field, week_field, url_field, email_field, color_field, time_field, range_field
  • 8. Form to an object http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html
  • 9. Setting up a form to an object # routes resources :developers # controller def new @developer = Developer.new end # view <%= form_for @developer do |f| %> <%= f.text_field :name %><br> <%= f.text_area :resume %><br> <%= f.submit %> <% end %> <form class="new_developer" id="new_developer" action="/developers" accept-charset="UTF-8" method="post"> <!-- autenticity_token and utf8 --> <input type="text" name="developer[name]" id="developer_name" /><br> <textarea name="developer[resume]" id="developer_resume"> </textarea><br> <input type="submit" name="commit" value="Create Developer" /> </form>
  • 10. Label <%= f.label :name %><br> <%= f.text_field :name %> <label for="developer_name">Name</label><br> <input type="text" name="developer[name]" id="developer_name" />
  • 11. Error messages # model class Developer < ActiveRecord::Base validates_presence_of :name end # view <% if @developer.errors.any? %> <ul> <% @developer.errors.full_messages.each do |msg| %> <li><%= msg %></li> <% end %> </ul> <% end %> <ul> <li>Name can't be blank</li> </ul>
  • 13. Select with array <%= f.select(:gender, { M: 1, F: 2 }, { include_blank: 'Choice' }) %> <select name="developer[gender]" id="developer_gender"> <option value="">Choice</option> <option selected="selected" value="1">M</option> <option value="2">F</option> </select> <select name="developer[gender]" id="developer_gender"> <option selected="selected" value="1">M</option> <option value="2">F</option> </select> <%= f.select(:gender, M: 1, F: 2) %>
  • 14. Select with collection <%= f.collection_select(:indication_id, Developer.all, :id, :name, { prompt: 'None' }) %> <select name="developer[indication_id]" id=" developer_indication_id"> <option value="">None</option> <option value="1">Linus</option> <option value="2">Bruno</option> </select> <select name="developer[indication_id]" id=" developer_indication_id"> <option value="1">Linus</option> <option value="2">Bruno</option> </select> <%= f.collection_select(:indication_id, Developer.all, :id, :name) %>
  • 16. Select <%= f.select( :gender, { M: 1, F: 2 }, { include_blank: 'Choice' }, { class: 'css-class', data: { id: 'gender', optional: true } } ) %> <select class="css-class" data-id="gender" data- optional="true" name="developer[gender]" id=" developer_gender">
  • 18. Configure model and controller # controller class DevelopersController < ApplicationController def new @developer = Developer.new @developer.addresses.build end def developer_params params.require(:developer).permit(:name, :resume, : gender, addresses_attributes: [:id, :name, :street]) end end # models class Address < ActiveRecord::Base belongs_to :developer end class Developer < ActiveRecord::Base has_many :addresses accepts_nested_attributes_for :addresses end
  • 19. Add nested form to view… <%= form_for @developer do |f| %> ... <%= f.fields_for :addresses do |addresses_form| %> <%= addresses_form.text_field :name %> <%= addresses_form.text_field :street %> <% end %> ... <% end %>
  • 20. … renders <input type="text" value="" name="developer[addresses_attributes][0][name]" id=" developer_addresses_attributes_0_name" /> <input type="text" value="" name="developer[addresses_attributes][0][street]" id=" developer_addresses_attributes_0_street" /> <input type="hidden" value="1" name="developer[addresses_attributes][0][id]" id=" developer_addresses_attributes_0_id" />
  • 21. That's all folks Bruno Almeida https://github.com/wwwbruno https://facebook.com/wwwbruno https://twitter.com/@wwwbruno http://www.slideshare.net/wwwbruno Any questions?