Routing Error : No route matches "/images/new" using scaffold code
I'm inexperienced with Rails, so I may be overlooking something basic, but I'm following the Paperclip wiki's documentation for adding image attachments and after modifying the related files as indicated there, /images/new
works as expected, until the form is submitted (form partial has been modified to include a file-upload field for the attachment in place of the generated database fields). The response is this:
Routing Error
No route matches "/images/new"
And the rails server outputs this:
Started POST "/images/new" for 127.0.0.1 at Tue Mar 15 16:19:45 -0500 2011
ActionController::RoutingError (No route matches "/images/new"):
Rendered /usr/lib/ruby/gems/1.8/gems/actionpack-3.0.5/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.0ms)
I created an Image model to allow for handling of each image attachment independently of the Project model which they will be associated with (haven't done any of that yet).
Here is my images/_form.html.erb :
<%= form_for :image, :as => @image, :html => { :multipart => true } do |f| %>
<% if @image.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@image.errors.count, "error") %> prohibited this image from being saved:</h2>
<ul>
<% @image.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
开发者_运维知识库 </div>
<% end %>
<div class="field">
<%= f.label :img %><br />
<%= f.file_field :img %>
</div>
<div class="field">
<%= f.label :project_id %><br />
<%= f.text_field :project_id %>
</div>
<div class="field">
<%= f.label :alt %><br />
<%= f.text_area :alt %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
And here is my routes.rb
App2::Application.routes.draw do
resources :images
resources :projects
get "pages/about"
get "pages/contact"
root :to => "projects#index"
end
And app/models/image.rb
:
class Image < ActiveRecord::Base
has_attached_file :img
# :styles => { :thumb => "150x150>",
# :large => "800x600>",
# :hd => "1920x1080>"
# }
end
Couldn't find any clear information related to this error that seemed relevant to my configuration, so I'd appreciate some more experienced eyes looking over this with me. I'll post more info if needed.
I was facing the same issue for some time now. I made the following changes in "form_for" -
<%= form_for :image, :as => @image, :url => { :action => "create" }, :html => { :multipart => true } do |f| %>
Now POST goes to /images and the missing route error message does not come anymore.
Change the form_for parameters like this:
<%= form_for @image, :html => { :multipart => true } do |f| %>
<% end %>
I have just tested it, it should work.
It seems the problem is related to Paperclip and/or ImageMagick, perhaps involving my Windows/Cygwin configuration. Changing some environment variables seems to have allowed me to bypass this issue and move onto the ....jpg is not recognized by the 'identify' command.
messages.
Any help on that would be appreciated but it looks like that's a topic that's already covered by existing questions, which I'm reading through now (no luck so far).
精彩评论