2014-01-10 1 views
0
# 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 

나는 그들이 순간에 포스트없이 존재할 수 있기 때문 (에 필요한 post_id를 지정하지 않고 삭제 할 수 있어야하지만 어떤 경로가 assets 올라올 없습니다 새로운 파일에 파일을 업로드하고 수신하려면이 파일을 주문하십시오.)는 레일에 중첩 된 리소스에 대한 탐지되지 않는 4 호선

라우트 assets#newassets#create 일 잘 아니지만 assets#destroy는 (I 오류가 DELETE /assets/<id>가 정의되지 않은 말을 얻는다.

도와주세요! :-)

+0

Rails가 이미지, 스크립트 및 스타일 시트를 저장하는 데 사용하는 디렉토리의 이름 인'assets'와 관련이 있습니다. '자산'을 다른 용도로 사용하려면 Rails가 해당 자산을 다른 곳에 배치하도록 구성해야합니다. – Ajedi32

답변

6

에 대한 작업을 파괴,

변경 route.rb의 행 (:delete 대신에 :destroy 고지)

resources :assets, only: [:new, :create, :destroy] 
+0

당신은 남자들 중에 신이 십니다! – nicohvi