Skip to content

Fix Rails 7+ mutating forum actions by replacing method links with button forms - #42

Merged
excid3 merged 1 commit into
excid3:masterfrom
aliumairdev:fix/41-rails7-nonjs-actions
Mar 11, 2026
Merged

Fix Rails 7+ mutating forum actions by replacing method links with button forms#42
excid3 merged 1 commit into
excid3:masterfrom
aliumairdev:fix/41-rails7-nonjs-actions

Conversation

@aliumairdev

Copy link
Copy Markdown
Contributor

Problem

Mutating forum actions relied on link_to ... method: (delete post, mark solved/unsolved, notification toggle). In Rails 7+ setups without rails-ujs, these links fall back to GET and the intended POST/PUT/DELETE actions do not execute.

Root Cause

link_to with method: depends on JavaScript interception via data-method.

Fix

  • Replace mutating link_to ... method: calls with button_to in:
    • forum post partial (delete, solved, unsolved)
    • discussion layout notification toggle
  • Keep the existing UI styling via button classes/form_class.

Tests

  • Added test/views/non_js_actions_test.rb to assert these mutating actions use button_to and no longer use link_to ... method:.
  • Ran:
    • bundle _2.7.1_ exec ruby test/views/non_js_actions_test.rb
    • bundle _2.7.1_ exec standardrb test/views/non_js_actions_test.rb

Fixes #41

Replace JS-dependent  usages in discussion views with  so post/delete/put actions work without rails-ujs (issue excid3#41).

Add a regression test covering forum post and notification templates to ensure these mutating actions stay non-JS form submissions.
@excid3
excid3 merged commit 1801be7 into excid3:master Mar 11, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

link_to method: :put or :delete or :post did not working on rails 7

2 participants