2011-03-28 30 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