I have four controllers.
Accounts, Databases, Folders and Contents
This links works perfectly.
<li><%= link_to t('global.delete').capitalize, folders_destroy_path(folder_id: folder[:folder_id]), :onclick => 'return confirm(\'Are you sure?\')' %></li>
<li><%= link_to t('global.delete').capitalize, databases_destroy_path(database_id: @database[:database_id]), :onclick => 'return confirm(\'Are you sure?\')' %></li>
Destroy folder
Started GET "/folders/destroy?folder_id=65f40c35329880e9e65206e7" for 83.32.215.26 at 2024-03-15 08:53:39 +0000
Processing by FoldersController#destroy as HTML
Parameters: {"folder_id"=>"65f40c35329880e9e65206e7"}
Destroy database
Started GET "/databases/destroy?database_id=65f40d38329880e9e65206e8" for 83.32.215.26 at 2024-03-15 08:57:31 +0000
Processing by DatabasesController#destroy as HTML
Parameters: {"database_id"=>"65f40d38329880e9e65206e8"}
With Accounts works too.
But NOT with contents.
This link...
<li><%= link_to t('global.delete').capitalize, contents_destroy_path(content_id: content[:content_id]), :onclick => 'return confirm(\'Are you sure?\')' %></li>
behaves like this....
Started GET "/contents/destroy?content_id=65f2d3ac3298803b035533e3" for 83.32.215.26 at 2024-03-15 09:01:51 +0000
Processing by ContentsController#show as HTML
Parameters: {"content_id"=>"65f2d3ac3298803b035533e3", "id"=>"destroy"}
In all cases, HTTP method and uri path + uri query are similar
But in Contents case, rails choose destroy as id parameter instead as an action. For action choose show. Same for other Contents actions as enable or disable
ActionController::MissingExactTemplate (ContentsController#show is missing a template for request formats: text/html):
My /my_app/config/routes.rb looks like this:
Rails.application.routes.draw do
devise_for :users
resources :contents
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
# Defines the root path route ("/")
root 'welcome#index'
get 'accounts/index'
get 'accounts/show'
post 'accounts/create'
get 'accounts/edit'
get 'accounts/destroy'
get 'databases/index'
get 'databases/show'
post 'databases/create'
post 'databases/update'
get 'databases/destroy'
get 'databases/backup'
get 'databases/build'
get 'databases/offload'
get 'databases/restore'
get 'folders/show'
post 'folders/create'
get 'folders/destroy'
post 'folders/update'
get 'folders/enable'
get 'folders/disable'
get 'contents/show'
post 'contents/create'
post 'contents/update'
get 'contents/destroy'
get 'contents/enable'
get 'contents/disable'
get 'contents/reprocess'
end
rails routes shows...
icalvete@dev:~/my_app$ bin/rails routes
Prefix Verb URI Pattern Controller#Action
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session GET /users/sign_out(.:format) devise/sessions#destroy
contents GET /contents(.:format) contents#index
POST /contents(.:format) contents#create
new_content GET /contents/new(.:format) contents#new
edit_content GET /contents/:id/edit(.:format) contents#edit
content GET /contents/:id(.:format) contents#show
PATCH /contents/:id(.:format) contents#update
PUT /contents/:id(.:format) contents#update
DELETE /contents/:id(.:format) contents#destroy
root GET / welcome#index
accounts_index GET /accounts/index(.:format) accounts#index
accounts_show GET /accounts/show(.:format) accounts#show
accounts_create POST /accounts/create(.:format) accounts#create
accounts_edit GET /accounts/edit(.:format) accounts#edit
accounts_destroy GET /accounts/destroy(.:format) accounts#destroy
databases_index GET /databases/index(.:format) databases#index
databases_show GET /databases/show(.:format) databases#show
databases_create POST /databases/create(.:format) databases#create
databases_update POST /databases/update(.:format) databases#update
databases_destroy GET /databases/destroy(.:format) databases#destroy
databases_backup GET /databases/backup(.:format) databases#backup
databases_build GET /databases/build(.:format) databases#build
databases_offload GET /databases/offload(.:format) databases#offload
databases_restore GET /databases/restore(.:format) databases#restore
folders_show GET /folders/show(.:format) folders#show
folders_create POST /folders/create(.:format) folders#create
folders_destroy GET /folders/destroy(.:format) folders#destroy
folders_update POST /folders/update(.:format) folders#update
folders_enable GET /folders/enable(.:format) folders#enable
folders_disable GET /folders/disable(.:format) folders#disable
contents_show GET /contents/show(.:format) contents#show
contents_create POST /contents/create(.:format) contents#create
contents_update POST /contents/update(.:format) contents#update
contents_destroy GET /contents/destroy(.:format) contents#destroy
contents_enable GET /contents/enable(.:format) contents#enable
contents_disable GET /contents/disable(.:format) contents#disable
contents_reprocess GET /contents/reprocess(.:format) contents#reprocess
jobs_index GET /jobs/index(.:format) jobs#index
jobs_show GET /jobs/show(.:format) jobs#show
POST /jobs/index(.:format) jobs#index
jobs_create POST /jobs/create(.:format) jobs#create
modifications_index GET /modifications/index(.:format) modifications#index
modifications_create POST /modifications/create(.:format) modifications#create
turbo_recede_historical_location GET /recede_historical_location(.:format) turbo/native/navigation#recede
turbo_resume_historical_location GET /resume_historical_location(.:format) turbo/native/navigation#resume
turbo_refresh_historical_location GET /refresh_historical_location(.:format) turbo/native/navigation#refresh
rails_postmark_inbound_emails POST /rails/action_mailbox/postmark/inbound_emails(.:format) action_mailbox/ingresses/postmark/inbound_emails#create
rails_relay_inbound_emails POST /rails/action_mailbox/relay/inbound_emails(.:format) action_mailbox/ingresses/relay/inbound_emails#create
rails_sendgrid_inbound_emails POST /rails/action_mailbox/sendgrid/inbound_emails(.:format) action_mailbox/ingresses/sendgrid/inbound_emails#create
rails_mandrill_inbound_health_check GET /rails/action_mailbox/mandrill/inbound_emails(.:format) action_mailbox/ingresses/mandrill/inbound_emails#health_check
rails_mandrill_inbound_emails POST /rails/action_mailbox/mandrill/inbound_emails(.:format) action_mailbox/ingresses/mandrill/inbound_emails#create
rails_mailgun_inbound_emails POST /rails/action_mailbox/mailgun/inbound_emails/mime(.:format) action_mailbox/ingresses/mailgun/inbound_emails#create
rails_conductor_inbound_emails GET /rails/conductor/action_mailbox/inbound_emails(.:format) rails/conductor/action_mailbox/inbound_emails#index
POST /rails/conductor/action_mailbox/inbound_emails(.:format) rails/conductor/action_mailbox/inbound_emails#create
new_rails_conductor_inbound_email GET /rails/conductor/action_mailbox/inbound_emails/new(.:format) rails/conductor/action_mailbox/inbound_emails#new
rails_conductor_inbound_email GET /rails/conductor/action_mailbox/inbound_emails/:id(.:format) rails/conductor/action_mailbox/inbound_emails#show
new_rails_conductor_inbound_email_source GET /rails/conductor/action_mailbox/inbound_emails/sources/new(.:format) rails/conductor/action_mailbox/inbound_emails/sources#new
rails_conductor_inbound_email_sources POST /rails/conductor/action_mailbox/inbound_emails/sources(.:format) rails/conductor/action_mailbox/inbound_emails/sources#create
rails_conductor_inbound_email_reroute POST /rails/conductor/action_mailbox/:inbound_email_id/reroute(.:format) rails/conductor/action_mailbox/reroutes#create
rails_conductor_inbound_email_incinerate POST /rails/conductor/action_mailbox/:inbound_email_id/incinerate(.:format) rails/conductor/action_mailbox/incinerates#create
rails_service_blob GET /rails/active_storage/blobs/redirect/:signed_id/*filename(.:format) active_storage/blobs/redirect#show
rails_service_blob_proxy GET /rails/active_storage/blobs/proxy/:signed_id/*filename(.:format) active_storage/blobs/proxy#show
GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs/redirect#show
rails_blob_representation GET /rails/active_storage/representations/redirect/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations/redirect#show
rails_blob_representation_proxy GET /rails/active_storage/representations/proxy/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations/proxy#show
GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations/redirect#show
rails_disk_service GET /rails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show
update_rails_disk_service PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update
rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format)
Although many people tell me about the HTTP method, and they are rigth, this is is not my real issue because other controller work even with GET.
The real issue is resources :contents in my /my_app/config/routes.rb
Deleting it, works perfectly.