2011-03-28 70 views
1

我正在開發一個rails 3項目。 我的模型之一是下列操作之一(它使用回形針上傳圖片)Rails 3,看不到我的「模型」_path

class Picture < ActiveRecord::Base 
    has_and_belongs_to_many :categories 
    has_attached_file :pict, 
       :styles => { :small => "150x150>" } 

    validates_attachment_presence :pict 
    validates_attachment_size :pict, :less_than => 5.megabytes 
    validates_attachment_content_type :pict, :content_type => ['image/jpeg', 'image/png', 'image/gif'] 

end 

在其index.html.erb,我已經加入了「的link_to」要刪除的記錄,但下面不工作:

undefined method `picture_path' for #<#<Class:0x10549f560>:0x10549d940> 

Extracted source (around line #16): 

8: <table class="gallery"> 
9: <tr> 
10: <% i=0 %> 
11: <% @pictures.each do |picture| %> 
12: <% if i%4 == 0 then %> 
13:  </tr><tr> 
14:  <% end%> 
15:  <td><%= link_to image_tag(picture.pict.url(:small)), picture.pict.url %></td> 
16:  <td><%= link_to image_tag("delete.png"), picture, :confirm => 'Are you sure?', :method => :delete %></td> 
17:  <% i=i+1 %> 
18: <% end %> 
19: </tr> 

我已經爲另一個模型使用同一行(16),我沒有這個錯誤。

請問您可以幫忙嗎?

感謝和問候,

呂克

回答

4

它看起來像你錯過了你的routes.rb文件 '圖片' 路線....

resources :pictures 
+0

嗯...你」正確。事實上,我在routes.rb文件中有'resources:pictures,:only => [:index,:new,:create]'(我真的不知道爲什麼......)。非常感謝。 – Luc 2011-03-28 09:57:47