我有以下兩種模式:的Rails 3 - 建立一個表單更新記錄
class PhotoAlbum < ActiveRecord::Base
belongs_to :project
has_many :photos, :dependent => :destroy
class Photo < ActiveRecord::Base
belongs_to :photo_album
當用戶查看照片,網址就像是如下:「/ photo_albums/40 /照片頁? = 6"
在這張照片視圖頁面(專輯裏)我想給用戶更新圖像的選項,所以我使用了以下內容:
<% form_for [:photo, @photos.first], :url => photo_album_photos_path, :html => { :multipart => true } do |f| %>
<form method="post" id="edit_photo_124" enctype="multipart/form-data" class="edit_photo" action="/photo_albums/40/photos" accept-charset="UTF-8">
我認爲這是正確的?問題是,當我點擊更新,我得到以下錯誤:
No route matches "/photo_albums/40/photos"
這裏是我的路線,這看起來不錯,不是嗎?
photo_album_photo PUT /photo_albums/:photo_album_id/photos/:id(.:format) {:action=>"update", :controller=>"photos"}
photo PUT /photos/:id(.:format) {:action=>"update", :controller=>"photos"}
想法?感謝
UPDATEW¯¯配置路由文件:
resources :photos do
resources :comments, :only => [:create, :update,:destroy], :constraint => {:context_type => "photos"}
collection do
post 'upload'
get 'search'
end
end
resources :photo_albums do
resources :comments, :only => [:create, :update,:destroy], :constraint => {:context_type => "photo_albums"}
resources :photos
collection do
get 'search'
end
end
沒關係,以後我需要這個「<%的form_for [:photo_album,@ photos.first]:URL => photo_album_photo_path,:HTML = > {:multipart => true} do | f |%>「試過,但是它出現錯誤」沒有路線匹配{:action =>「destroy」,:controller =>「photos」}「有趣的是我有一個缺點我正在嘗試更新不會銷燬。 – TheExit 2010-11-01 18:35:28
使用我的路線更新 – TheExit 2010-11-01 18:40:13
在更新:url arg後,