2011-03-22 158 views
0

我创建了一个叫做折叠的小应用程序,我已经分配了几个参数。我决定,我想为每个折叠添加一张照片,并通过回形针教程。导轨路由错误

所以,现在我已经安装了回形针和ImageMagick的,当我编辑折,我可以从我的硬盘驱动器选择一个图像,当我点击更新倍我得到那个说

路由路由错误错误

No route matches "/folds/2/edit" 

我很新的这一点,所以我能加入,将让我一个明确的答案? 耙路线?

fold_comments GET /folds/:fold_id/comments(.:format)   {:action=>"index", :controller=>"comments"} 
fold_comments POST /folds/:fold_id/comments(.:format)   {:action=>"create", :controller=>"comments"} 
new_fold_comment GET /folds/:fold_id/comments/new(.:format)  {:action=>"new", :controller=>"comments"} 
edit_fold_comment GET /folds/:fold_id/comments/:id/edit(.:format) {:action=>"edit", :controller=>"comments"} 
fold_comment GET /folds/:fold_id/comments/:id(.:format)  {:action=>"show", :controller=>"comments"} 
fold_comment PUT /folds/:fold_id/comments/:id(.:format)  {:action=>"update", :controller=>"comments"} 
fold_comment DELETE /folds/:fold_id/comments/:id(.:format)  {:action=>"destroy", :controller=>"comments"} 
     folds GET /folds(.:format)       {:action=>"index", :controller=>"folds"} 
     folds POST /folds(.:format)       {:action=>"create", :controller=>"folds"} 
    new_fold GET /folds/new(.:format)      {:action=>"new", :controller=>"folds"} 
    edit_fold GET /folds/:id/edit(.:format)     {:action=>"edit", :controller=>"folds"} 
     fold GET /folds/:id(.:format)      {:action=>"show", :controller=>"folds"} 
     fold PUT /folds/:id(.:format)      {:action=>"update", :controller=>"folds"} 
     fold DELETE /folds/:id(.:format)      {:action=>"destroy", :controller=>"folds"} 
    home_index GET /home/index(.:format)      {:controller=>"home", :action=>"index"} 
     root  /(.:format)         {:controller=>"home", :action=>"index"} 

fold.rb?

class Fold < ActiveRecord::Base 
validates :model, :presence => true 
validates :folder, :presence => true 
has_many :comments, :dependent => :destroy 
has_attached_file :photo, :styles => { :small => "150x150>" }, 
       :url => "/assets/folds/:id/:style/:basename.:extension", 
       :path => ":rails_root/public/assets/folds/:id/:style/:basename.:extension", 
       :dependent => :destroy 
validates_attachment_presence :photo 
validates_attachment_size :photo, :less_than => 5.megabytes 
validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png'] 
end 

的routes.rb

Folds::Application.routes.draw do 
    resources :folds do 
resources :comments 
    end 
    get "home/index" 
end 

_form.html.erb

<%= form_for :fold, :html => { :multipart => true } do |f| %> 
<% if @fold.errors.any? %> 
<div id="error_explanation"> 
    <h2><%= pluralize(@fold.errors.count, "error") %> prohibited this fold from being saved:</h2> 
    <ul> 
    <% @fold.errors.full_messages.each do |msg| %> 
    <li><%= msg %></li> 
    <% end %> 
    </ul> 
</div> 
<% end %> 
<div class="field"> 
<%= f.label :model %><br /> 
<%= f.text_field :model %> 
</div> 
<div class="field"> 
<%= f.file_field :photo_file_name %> 
</div> 
<div class="field"> 
<%= f.label :folder %><br /> 
<%= f.text_field :folder %> 
</div> 
<div class="field"> 
<%= f.label :base %><br /> 
<%= f.text_field :base %> 
</div> 
<div class="field"> 
<%= f.label :creator %><br /> 
<%= f.text_field :creator %> 
</div> 
<div class="field"> 
<%= f.label :body %><br /> 
<%= f.text_area :body %> 
</div> 
<div class="field"> 
<%= f.label :fold_id %><br /> 
<%= f.text_field :fold_id %> 
</div> 
<div class="field"> 
<%= f.label :diagram %><br /> 
<%= f.text_field :diagram %> 
</div> 
<div class="actions"> 
<%= f.submit %> 
</div> 
<% end %> 
+1

你能张贴'配置/ routes.rb'和你得到这个错误的看法? – 2011-03-22 21:30:39

+0

已添加,其他的帮助? – Jeff 2011-03-22 23:20:45

回答

0

如果您认为一号线改为

<%= form_for @fold, :html => { :multipart => true } do |f| %> 

,改变

<%= f.file_field :photo_file_name %> 

<%= f.file_field :photo %> 
+0

我得到ActionController :: RoutingError(没有路由匹配“/ assets/fold/2/small”): 但它并没有打破整个应用程序。图片仍然没有上传,所以我有一个断开的链接。那是干什么的? – Jeff 2011-03-23 00:06:39

+0

这应该修复您的编辑路线并创建操作。至于为什么图片没有上传?我注意到另一件事(我会更新答案)。你的日志说什么?回形针往往会给出非常详细的输出。 – 2011-03-23 12:59:50