回形针和导轨3 - NoMethodError

时间:2010-11-06 04:10:15

标签: ruby-on-rails-3 ruby-on-rails-plugins paperclip

所以我刚刚安装了paperclip,并试图让它在我全新的Rails应用程序中运行。

但是当我转到localhost / upload / new:

时,这是我一直得到的错误
NoMethodError in Upload#new
undefined method `uploads_path' for #<#<Class:0x00000102d1b8e0>:0x00000102cf24e0>
Extracted source (around line #3):

1: <h1>Upload Images</h1>
2: 
3: <%= form_for @upload, :html => { :multipart => true } do |f| %>
4:  <%= render 'fields', :f => f %>
5:  <div>
6:      <%= f.submit "Upload" %>

我用Paperclip解决了另一个错误,在config / application.rb文件中包含以下行:

Paperclip::Railtie.insert 

我的应用程序结构的方式是我创建了一个名为“上传”的模型,因为该应用程序将管理各种文件类型 - 由用户上传。 Paperclip正在管理图像。

上传控制器如下所示:

class UploadController < ApplicationController
  def index
  end

  def show
  end

  def new
    @upload = Upload.new
    @title = "Upload"
  end

  def edit
  end

  def delete
  end

end

所以我的上传模型如下所示:

class Upload < ActiveRecord::Base
    attr_accessible :name, :description, :type

    has_attached_file :image
end

这是我的new.html.erb文件的外观:

<h1>Upload Images</h1>

<%= form_for @upload, :html => { :multipart => true } do |f| %>
    <%= render 'fields', :f => f %>
    <div>
        <%= f.submit "Upload" %>
    </div>
<% end %>

部分看起来像这样:

<%= render 'shared/error_messages', :object => f.object %>
<div class="field">
    <%= f.label :name %><br />
    <%= f.text_field :name %>
</div>
<div class="field">
    <%= f.label :description %><br />
    <%= f.text_field :description %>
</div>
<div class="field">
    <%= f.label :type %><br />
    <%= f.text_field :type %>
</div>
<div class="field">
    <%= f.file_field :image %>
</div>

P.S。我只是在学习Rails,所以如果有菜鸟/菜鸟的错误,请不要把我钉在十字架上:|

感谢。

编辑:这是应用程序的耙路线输出,正如Zabba所说:

comment_index GET /comment/index(.:format)   {:controller=>"comment", :action=>"index"}
   comment_show GET /comment/show(.:format)    {:controller=>"comment", :action=>"show"}
    comment_new GET /comment/new(.:format)     {:controller=>"comment", :action=>"new"}
   comment_edit GET /comment/edit(.:format)    {:controller=>"comment", :action=>"edit"}
 comment_delete GET /comment/delete(.:format)  {:controller=>"comment", :action=>"delete"}
   upload_index GET /upload/index(.:format)    {:controller=>"upload", :action=>"index"}
    upload_show GET /upload/show(.:format)     {:controller=>"upload", :action=>"show"}
     upload_new GET /upload/new(.:format)      {:controller=>"upload", :action=>"new"}
    upload_edit GET /upload/edit(.:format)     {:controller=>"upload", :action=>"edit"}
  upload_delete GET /upload/delete(.:format)   {:controller=>"upload", :action=>"delete"}
  project_index GET /project/index(.:format)   {:controller=>"project", :action=>"index"}
   project_show GET /project/show(.:format)    {:controller=>"project", :action=>"show"}
    project_new GET /project/new(.:format)     {:controller=>"project", :action=>"new"}
   project_edit GET /project/edit(.:format)    {:controller=>"project", :action=>"edit"}
 project_delete GET /project/delete(.:format)  {:controller=>"project", :action=>"delete"}
   client_index GET /client/index(.:format)    {:controller=>"client", :action=>"index"}
    client_show GET /client/show(.:format)     {:controller=>"client", :action=>"show"}
     client_new GET /client/new(.:format)      {:controller=>"client", :action=>"new"}
    client_edit GET /client/edit(.:format)     {:controller=>"client", :action=>"edit"}
  client_delete GET /client/delete(.:format)   {:controller=>"client", :action=>"delete"}
 designer_index GET /designer/index(.:format)  {:controller=>"designer", :action=>"index"}
  designer_show GET /designer/show(.:format)   {:controller=>"designer", :action=>"show"}
   designer_new GET /designer/new(.:format)    {:controller=>"designer", :action=>"new"}
  designer_edit GET /designer/edit(.:format)   {:controller=>"designer", :action=>"edit"}
designer_delete GET /designer/delete(.:format) {:controller=>"designer", :action=>"delete"}
           root     /(.:format)                {:controller=>"project", :action=>"index"}

1 个答案:

答案 0 :(得分:1)

在地图文件中,添加:

对于Rails 2.x:

map.resources :uploads

对于Rails 3.x:

resources :uploads

这将添加7个RESTful操作的所有路由,然后users_path将起作用。