Skip to content

Commit 1435262

Browse files
authored
Merge pull request #67 from isleofruby/feature/form_with
Switch to Rails 5.1's form_with, misc form improvements
2 parents 40d219c + 557d5ed commit 1435262

File tree

7 files changed

+51
-34
lines changed

7 files changed

+51
-34
lines changed
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
= form_tag activity_path(activity), method: :delete do
1+
= form_with url: activity_path(activity), method: :delete do |f|
22

33
%fieldset
44
%label.inline
55
= check_box_tag :confirm_delete
66
= t('delete_activity_form.confirmation', count: activity.participants.count)
77

8-
= button_tag t('delete_activity_form.submit')
8+
= f.button t('delete_activity_form.submit')

app/views/activities/_form.html.haml

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
= form_for activity, html: { id: 'new-activity' } do |f|
1+
= form_with model: activity, id: 'new-activity' do |f|
22

33
%label.name
44
= f.text_field :name, placeholder: t('activity_form.name.label'), class: 'title'
@@ -13,7 +13,7 @@
1313
%span.between
1414
= t('common.or').downcase
1515
%label.inline
16-
= f.check_box :anytime
16+
= f.check_box :anytime, id: 'activity_anytime'
1717
= t('activity_form.anytime.hint')
1818

1919
%hr
@@ -47,11 +47,13 @@
4747
= t('activity_form.description.hint')
4848

4949
%label.image-url
50-
= f.url_field :image_url, placeholder: t('activity_form.image_url.label')
50+
= f.url_field :image_url,
51+
id: 'activity_image_url',
52+
placeholder: t('activity_form.image_url.label')
5153
.preview
5254
%small
5355
= t('activity_form.image_url.hint')
5456

55-
%button{ type: 'submit' }>
57+
= f.button do
5658
%span>
5759
= t("common.submit.#{activity.new_record? ? 'new' : 'edit'}")

app/views/passwords/new.html.haml

+8-5
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44
Reset your password
55

66
%section.form
7-
= form_for resource, as: resource_name, url: password_path(resource_name), method: :post do |f|
7+
= form_with model: resource, scope: resource_name,
8+
url: password_path(resource_name),
9+
method: :post do |f|
810
-# %p Send me reset password instructions to this email address:
911
1012
%label.email
11-
%span.label Email address
12-
= f.email_field :email, placeholder: 'You email address'
13+
%span.label Your email address
14+
= f.email_field :email,
15+
autocomplete: 'email',
16+
placeholder: 'Your email address'
1317

14-
%button{ type: 'submit' }>
15-
Send me instructions
18+
= f.button 'Send me instructions'
1619

1720
%p.info
1821
= succeed '.' do

app/views/registrations/edit.html.haml

+12-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
Edit profile
55

66
%section.form
7-
= form_for resource, as: resource_name, url: registration_path(resource_name) do |f|
7+
= form_with model: resource, scope: resource_name,
8+
url: registration_path(resource_name) do |f|
89

910
%figure.avatar
1011
= image_tag(avatar_url(@user, 128))
@@ -15,7 +16,9 @@
1516

1617
%label.email
1718
%span.label Your email address
18-
= f.email_field :email, placeholder: 'Your email address'
19+
= f.email_field :email,
20+
autocomplete: 'email',
21+
placeholder: 'Your email address'
1922

2023
%label.inline.show_participation
2124
= f.check_box :show_participation
@@ -24,14 +27,17 @@
2427
- if resource.no_oauth_connected?
2528
%label.password
2629
%span.label Your password
27-
= f.password_field :password, placeholder: 'Your password'
30+
= f.password_field :password,
31+
autocomplete: 'new-password',
32+
placeholder: 'Your password'
2833

2934
%label.password
3035
%span.label Your password once more
31-
= f.password_field :password_confirmation, placeholder: 'Your password once more'
36+
= f.password_field :password_confirmation,
37+
autocomplete: 'new-password',
38+
placeholder: 'Your password once more'
3239

33-
%button{ type: 'submit' }>
34-
Update
40+
= f.button 'Update'
3541

3642
%p.divider
3743
%span Connect!

app/views/registrations/new.html.haml

+16-7
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,37 @@
1111
%p.divider
1212
%span or
1313

14-
= form_for resource, as: resource_name, url: registration_path(resource_name) do |f|
14+
= form_with model: resource, scope: resource_name,
15+
url: registration_path(resource_name) do |f|
1516
%h4= during_oauth_flow? ? 'One step more - we need your email address' : 'Register a new account'
1617

1718
%label.name
1819
%span.label Name
19-
= f.text_field :name, autofocus: true, placeholder: 'Name'
20+
= f.text_field :name,
21+
autofocus: true,
22+
autocomplete: 'name',
23+
placeholder: 'Name'
2024

2125
%label.email
2226
%span.label Email address
23-
= f.email_field :email, placeholder: 'Email address'
27+
= f.email_field :email,
28+
autocomplete: 'email',
29+
placeholder: 'Email address'
2430

2531
- if @user.password_required?
2632
%label.password
2733
%span.label Password
28-
= f.password_field :password, placeholder: 'Password'
34+
= f.password_field :password,
35+
autocomplete: 'new-password',
36+
placeholder: 'Password'
2937

3038
%label.password
3139
%span.label Password, once more
32-
= f.password_field :password_confirmation, placeholder: 'Password once more'
40+
= f.password_field :password_confirmation,
41+
autocomplete: 'new-password',
42+
placeholder: 'Password once more'
3343

34-
%button{ type: 'submit' }>
35-
Sign up
44+
= f.button 'Sign up'
3645

3746
%p.info
3847
= succeed '.' do

app/views/sessions/new.html.haml

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@
44
Sign in
55

66
%section.form
7-
= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f|
7+
= form_with model: resource, scope: resource_name,
8+
url: session_path(resource_name) do |f|
89

910
%label.email
1011
%span.label Your email address
11-
= f.email_field :email, autofocus: true, placeholder: 'Your email address'
12+
= f.email_field :email,
13+
autofocus: true,
14+
autocomplete: 'email',
15+
placeholder: 'Your email address'
1216

1317
%label.password
1418
%span.label Your password
1519
= f.password_field :password, placeholder: 'Your password'
1620

17-
%button{ type: 'submit' }>
18-
Sign in
21+
= f.button 'Sign in'
1922

2023
%p.divider
2124
%span or

config/initializers/new_framework_defaults.rb

-6
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
#
77
# Read the Guide for Upgrading Ruby on Rails for more info on each option.
88

9-
# Enable per-form CSRF tokens. Previous versions had false.
10-
Rails.application.config.action_controller.per_form_csrf_tokens = false
11-
12-
# Enable origin-checking CSRF mitigation. Previous versions had false.
13-
Rails.application.config.action_controller.forgery_protection_origin_check = false
14-
159
# Make Ruby 2.4 preserve the timezone of the receiver when calling `to_time`.
1610
# Previous versions had false.
1711
ActiveSupport.to_time_preserves_timezone = false

0 commit comments

Comments
 (0)