rails icon indicating copy to clipboard operation
rails copied to clipboard

Setting an assets prefix leads to 405 errors on POST requests

Open maxlein opened this issue 2 months ago • 0 comments

I try to get my app running under a special path with RAILS_RELATIVE_URL_ROOT.
I do that because my app runs in a kubernetes cluster and I need a specific route, e.g.: localhost/team-tracker
But if I set the assets prefix path, the site and styles are working but the POST request are failing like that:

POST http://127.0.0.1:3000/team-tracker/import_external_issues 405

RAILS_RELATIVE_URL_ROOT = /team-tracker

I have my routes scoped like that:

routes.rb

Rails.application.routes.draw do
  
  scope ENV['RAILS_RELATIVE_URL_ROOT'] || '/' do
    resources :board_issues
    resources :board_lists
    resources :homes

    post 'import_external_issues', to: 'issues#import_external_issues'

  end
end

Then I set an assets prefix, so that my assets are linked correctly:
development.rb
config.assets.prefix = ENV['RAILS_RELATIVE_URL_ROOT'] || '/assets'

But this step breaks the POST requests.

Am I dong something wrong? Is there an easier way to use an ingress with a special route?

Steps to reproduce

Set RAILS_RELATIVE_URL_ROOT and a corresponding assets prefix.

Expected behavior

POST requests are working the same like without setting the assets prefix.

Actual behavior

POST requests don't work: POST http://127.0.0.1:3000/team-tracker/import_external_issues 405

System configuration

Rails version: 7.1.2

Ruby version: 3.3.0

maxlein avatar Feb 22 '24 12:02 maxlein