2012-04-27 51 views
0

Picture模型,可以包含2場照片和描述(照片是現場從papperclip寶石)軌form_helper找不到在編輯頁面模型路徑

,我有PicturesController包含新創建編輯更新銷燬並顯示

我已申報routes.rb使用resource :pictures並且有我的路線。

 pictures POST /pictures(.:format)  pictures#create 
new_pictures GET /pictures/new(.:format) pictures#new 
edit_pictures GET /pictures/edit(.:format) pictures#edit 
       GET /pictures(.:format)  pictures#show 
       PUT /pictures(.:format)  pictures#update 
       DELETE /pictures(.:format)  pictures#destroy 

還有就是我的視圖代碼

# pictures/new.html.erb & pictures/edit.html.erb 
    <%= form_for @picture, :html => {:multipart => true} do |f| %> 

     <div><%= f.label :photo %><br/> 
     <%= f.file_field :photo %></div><br/> 

     <div><%= f.label :description %><br/> 
     <%= f.text_area :description %></div><br/> 

     <%= f.submit :upload %> 
    <% end %> 

    # 

我使用新的和編輯只需更改提交按鈕標籤相同的代碼。

new.html.erb工作正常(創建並保存圖片到數據庫中)。

但錯誤是出現在edit.html.erb

undefined method `picture_path' for #<#<Class:0x007f830e93ad30>:0x007f830e92d5b8> 

我已經檢查@picture。爲什麼rails無法找到Picture類的更新路徑?

我按照這個link的form_for指導。

任何想法?謝謝。

+0

請爲'new'和'edit'操作添加代碼。 – Thilo 2012-04-27 07:42:28

+0

@Thilo問題出在我的路線上。謝謝你的答案。 :) – Rafaiel 2012-04-27 07:58:51

回答

2

你的複數化有些問題。隨着資源:照片,你應該有這樣的事情..

pictures  GET /pictures(.:format)     pictures#index 
      POST /pictures(.:format)     pictures#create 
new_picture GET /pictures/new(.:format)    pictures#new 
edit_picture GET /pictures/:id/edit(.:format)   pictures#edit 
picture  GET /pictures/:id(.:format)    pictures#show 
      PUT /pictures/:id(.:format)    pictures#update 
      DELETE /pictures/:id(.:format)    pictures#destroy 

注意像素..這會產生動態picture_path方法

上的更新奇:變「資源」到「資源」在您的路線文件,你應該沒問題

+0

是的,你現在的工作。我有一段時間感到啞巴。感謝:D – Rafaiel 2012-04-27 07:57:13

+0

每個使用Rails的人在某個時候都被複數問題困住了;-) – 2012-04-27 07:58:35

+0

哈哈哈。我同意。 (第一次我發現與表名並被卡住了2天。):) – Rafaiel 2012-04-27 08:03:39