Reputation: 2270
# routes.rb
resources :assets, only: [:new, :create, :delete]
# asset.rb
class Asset < ActiveRecord::Base
belongs_to :post
end
# rake routes
Prefix Verb URI Pattern Controller#Action
post_comments POST /posts/:post_id/comments(.:format) comments#create
new_post_comment GET /posts/:post_id/comments/new(.:format) comments#new
posts GET /posts(.:format) posts#index
POST /posts(.:format) posts#create
new_post GET /posts/new(.:format) posts#new
edit_post GET /posts/:id/edit(.:format) posts#edit
post GET /posts/:id(.:format) posts#show
PATCH /posts/:id(.:format) posts#update
PUT /posts/:id(.:format) posts#update
DELETE /posts/:id(.:format) posts#destroy
post_form POST /post_form(.:format) posts#form
root GET / posts#index
No routes show up for assets
, though I need to be able to delete them without specifying a post_id, because they can exist without a post at the moment (necessary in order to be able to upload files and recerence these files in the new post).
The routes assets#new
and assets#create
work just fine, but not assets#destroy
(I get an error saying DELETE /assets/<id>
is undefined.
Help please! :-)
Upvotes: 0
Views: 92
Reputation: 29349
For destroy to work,
Change the line in your route.rb(notice :destroy
instead of :delete
)
resources :assets, only: [:new, :create, :destroy]
Upvotes: 6