Skip to content

Commit 0a38755

Browse files
committed
Migrate link_to to button_to for stateful actions in views
For these actions, we use use a non-default `method` (other than `GET`). To indicate that within the DOM (i.e., for Screenreaders) but also enhance compatibility with Turbo, we switch to proper `button_to` forms here. As part of this migration, some buttons should still be shown inline (hence, we add the `form_class: 'd-inline-block'`) or with the same height as regular links (hence, we add `class: 'h-100'`). See https://github.com/heartcombo/devise/wiki/How-To:-Upgrade-to-Devise-4.9.0-%5BHotwire-Turbo-integration%5D#data-method-vs-data-turbo-method See https://gorails.com/episodes/link_to-vs-button_to-in-rails
1 parent 3b0d2b7 commit 0a38755

File tree

24 files changed

+31
-31
lines changed

24 files changed

+31
-31
lines changed

app/views/application/_session.html.slim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
- if current_user.admin? || current_user.teacher? || current_user.internal_user?
1818
li = link_to(t('consumers.show.link'), current_user.consumer, class: 'dropdown-item') if current_user.consumer && policy(current_user.consumer).show?
1919
li = link_to(t('internal_users.show.link'), current_user, class: 'dropdown-item') if policy(current_user).show?
20-
li = link_to(t('sessions.destroy.link'), sign_out_path, method: :delete, class: 'dropdown-item')
20+
li = button_to(t('sessions.destroy.link'), sign_out_path, method: :delete, class: 'dropdown-item')
2121
- elsif current_user.webauthn_configured?
22-
li = link_to(t('sessions.destroy.link'), sign_out_path, method: :delete, class: 'dropdown-item')
22+
li = button_to(t('sessions.destroy.link'), sign_out_path, method: :delete, class: 'dropdown-item')
2323
- else
24-
li = link_to(t('sessions.destroy.link'), sign_out_path, method: :delete, class: 'dropdown-item')
24+
li = button_to(t('sessions.destroy.link'), sign_out_path, method: :delete, class: 'dropdown-item')
2525
- else
2626
li.nav-item = link_to(sign_in_path, class: 'nav-link') do
2727
i.fa-solid.fa-arrow-right-to-bracket

app/views/codeharbor_links/_form.html.slim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
.actions
1616
= render('shared/submit_button', f:, object: @codeharbor_link)
1717
- if @codeharbor_link.persisted?
18-
= link_to(t('codeharbor_link.delete'), polymorphic_path([@codeharbor_link.user, @codeharbor_link]), data: {confirm: t('shared.confirm_destroy')}, method: :delete, class: 'btn btn-danger float-end')
18+
= button_to(t('codeharbor_link.delete'), polymorphic_path([@codeharbor_link.user, @codeharbor_link]), data: {confirm: t('shared.confirm_destroy')}, method: :delete, class: 'btn btn-danger float-end')

app/views/consumers/index.html.slim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ h1 = Consumer.model_name.human(count: :other)
1212
td = link_to_if(policy(consumer).show?, consumer.name, consumer)
1313
td = link_to(t('shared.show'), consumer) if policy(consumer).show?
1414
td = link_to(t('shared.edit'), edit_consumer_path(consumer)) if policy(consumer).edit?
15-
td = link_to(t('shared.destroy'), consumer, data: {confirm: t('shared.confirm_destroy')}, method: :delete) if policy(consumer).destroy?
15+
td = button_to(t('shared.destroy'), consumer, data: {confirm: t('shared.confirm_destroy')}, method: :delete, class: 'btn btn-sm btn-link') if policy(consumer).destroy?
1616

1717
= render('shared/pagination', collection: @consumers)
1818
p = render('shared/new_button', model: Consumer)

app/views/error_template_attributes/index.html.slim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ h1 = ErrorTemplateAttribute.model_name.human(count: :other)
2323
code = error_template_attribute.regex
2424
td = link_to(t('shared.show'), error_template_attribute) if policy(error_template_attribute).show?
2525
td = link_to(t('shared.edit'), edit_error_template_attribute_path(error_template_attribute)) if policy(error_template_attribute).edit?
26-
td = link_to(t('shared.destroy'), error_template_attribute, data: {confirm: t('shared.confirm_destroy')}, method: :delete) if policy(error_template_attribute).destroy?
26+
td = button_to(t('shared.destroy'), error_template_attribute, data: {confirm: t('shared.confirm_destroy')}, method: :delete, class: 'btn btn-sm btn-link') if policy(error_template_attribute).destroy?
2727

2828
= render('shared/pagination', collection: @error_template_attributes)
2929
p = render('shared/new_button', model: ErrorTemplateAttribute)

app/views/error_templates/index.html.slim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ h1 = ErrorTemplate.model_name.human(count: :other)
1616
td = link_to(error_template.execution_environment)
1717
td = link_to(t('shared.show'), error_template) if policy(error_template).show?
1818
td = link_to(t('shared.edit'), edit_error_template_path(error_template)) if policy(error_template).edit?
19-
td = link_to(t('shared.destroy'), error_template, data: {confirm: t('shared.confirm_destroy')}, method: :delete) if policy(error_template).destroy?
19+
td = button_to(t('shared.destroy'), error_template, data: {confirm: t('shared.confirm_destroy')}, method: :delete, class: 'btn btn-sm btn-link') if policy(error_template).destroy?
2020

2121
= render('shared/pagination', collection: @error_templates)
2222
p = render('shared/new_button', model: ErrorTemplate)

app/views/error_templates/show.html.slim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ h2.mt-4
3535
code = attribute.regex
3636
td = link_to(t('shared.show'), attribute) if policy(attribute).show?
3737
td = link_to(t('shared.edit'), edit_error_template_attribute_path(attribute)) if policy(attribute).edit?
38-
td = link_to(t('shared.destroy'), attribute_error_template_url(error_template_attribute_id: attribute.id), method: :delete) if policy(attribute).destroy?
38+
td = button_to(t('shared.destroy'), attribute_error_template_url(error_template_attribute_id: attribute.id), method: :delete, class: 'btn btn-sm btn-link') if policy(attribute).destroy?
3939

4040
#add-attribute
4141
= collection_select({}, :error_template_attribute_id,

app/views/execution_environments/index.html.slim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ h1.d-inline-block = ExecutionEnvironment.model_name.human(count: :other)
3131
td = execution_environment.permitted_execution_time
3232
td = link_to(t('shared.show'), execution_environment) if policy(execution_environment).show?
3333
td = link_to(t('shared.edit'), edit_execution_environment_path(execution_environment)) if policy(execution_environment).edit?
34-
td = link_to(t('shared.destroy'), execution_environment, data: {confirm: t('shared.confirm_destroy')}, method: :delete) if policy(execution_environment).destroy?
34+
td = button_to(t('shared.destroy'), execution_environment, data: {confirm: t('shared.confirm_destroy')}, method: :delete, class: 'btn btn-sm btn-link') if policy(execution_environment).destroy?
3535
td = link_to(t('.shell'), shell_execution_environment_path(execution_environment)) if policy(execution_environment).shell?
3636
td = link_to(t('shared.statistics'), statistics_execution_environment_path(execution_environment)) if policy(execution_environment).statistics?
3737

app/views/execution_environments/show.html.slim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ h1.d-inline-block = @execution_environment
33
= render('shared/edit_button', object: @execution_environment)
44
button.btn.btn-secondary.float-end.dropdown-toggle data-bs-toggle='dropdown' type='button'
55
ul.dropdown-menu.dropdown-menu-end role='menu'
6-
li = link_to(t('execution_environments.index.synchronize.button'), sync_to_runner_management_execution_environment_path(@execution_environment), method: :post, class: 'dropdown-item') if policy(@execution_environment).sync_to_runner_management?
6+
li = button_to(t('execution_environments.index.synchronize.button'), sync_to_runner_management_execution_environment_path(@execution_environment), method: :post, class: 'dropdown-item') if policy(@execution_environment).sync_to_runner_management?
77
li = link_to(t('execution_environments.index.shell'), shell_execution_environment_path(@execution_environment), class: 'dropdown-item') if policy(@execution_environment).shell?
88
li = link_to(t('shared.statistics'), statistics_execution_environment_path(@execution_environment), 'data-turbo': 'false', class: 'dropdown-item') if policy(@execution_environment).statistics?
9-
li = link_to(t('shared.destroy'), @execution_environment, data: {confirm: t('shared.confirm_destroy')}, method: :delete, class: 'dropdown-item') if policy(@execution_environment).destroy?
9+
li = button_to(t('shared.destroy'), @execution_environment, data: {confirm: t('shared.confirm_destroy')}, method: :delete, class: 'dropdown-item') if policy(@execution_environment).destroy?
1010

1111
= row(label: 'execution_environment.name', value: @execution_environment.name)
1212
= row(label: 'execution_environment.user', value: link_to_if(policy(@execution_environment.author).show?, @execution_environment.author, @execution_environment.author))

app/views/exercise_collections/index.html.slim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ h1 = ExerciseCollection.model_name.human(count: :other)
1919
td = link_to(t('shared.show'), collection) if policy(collection).show?
2020
td = link_to(t('shared.edit'), edit_exercise_collection_path(collection)) if policy(collection).edit?
2121
td = link_to(t('shared.statistics'), statistics_exercise_collection_path(collection)) if policy(collection).statistics?
22-
td = link_to(t('shared.destroy'), collection, data: {confirm: t('shared.confirm_destroy')}, method: :delete) if policy(collection).destroy?
22+
td = button_to(t('shared.destroy'), collection, data: {confirm: t('shared.confirm_destroy')}, method: :delete, class: 'btn btn-sm btn-link') if policy(collection).destroy?
2323

2424
= render('shared/pagination', collection: @exercise_collections)
2525
p = render('shared/new_button', model: ExerciseCollection)

app/views/exercises/index.html.slim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ h1 = Exercise.model_name.human(count: :other)
5151
li = link_to(UserExerciseFeedback.model_name.human(count: :other), feedback_exercise_path(exercise), class: 'dropdown-item') if policy(exercise).feedback?
5252
li = link_to(RequestForComment.model_name.human(count: :other), exercise_request_for_comments_path(exercise), class: 'dropdown-item') if policy(exercise).rfcs_for_exercise?
5353
li = link_to(ProgrammingGroup.model_name.human(count: :other), exercise_programming_groups_path(exercise), class: 'dropdown-item') if policy(exercise).programming_groups_for_exercise?
54-
li = link_to(t('shared.destroy'), exercise, data: {confirm: t('shared.confirm_destroy')}, method: :delete, class: 'dropdown-item') if policy(exercise).destroy?
55-
li = link_to(t('.clone'), clone_exercise_path(exercise), data: {confirm: t('shared.confirm_destroy')}, method: :post, class: 'dropdown-item') if policy(exercise).clone?
54+
li = button_to(t('shared.destroy'), exercise, data: {confirm: t('shared.confirm_destroy')}, method: :delete, class: 'dropdown-item') if policy(exercise).destroy?
55+
li = button_to(t('.clone'), clone_exercise_path(exercise), data: {confirm: t('shared.confirm_destroy')}, method: :post, class: 'dropdown-item') if policy(exercise).clone?
5656
li = link_to(t('exercises.export_codeharbor.label'), '', class: 'dropdown-item export-start', data: {'exercise-id': exercise.id, 'bs-toggle': 'modal', 'bs-target': '#transfer-modal'}) if policy(exercise).export_external_confirm?
5757
li = link_to(t('exercises.download_proforma.label'), download_proforma_exercise_path(exercise), class: 'dropdown-item', target: '_blank', rel: 'noopener noreferrer') if policy(exercise).download_proforma?
5858

0 commit comments

Comments
 (0)