0

我创建了一个名为 folds 的小应用程序,并为其分配了一些参数。我决定要在每个折叠处添加一张照片,并完成了回形针教程。

所以现在我已经安装了回形针和 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"}

折叠.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

路线.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 %>
4

1 回答 1

0

如果您将视图的第一行更改为

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

和改变

<%= f.file_field :photo_file_name %>

<%= f.file_field :photo %>
于 2011-03-22T23:50:41.463 回答