2011-03-22 157 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