我在我的用户头像应用程序上使用paperclip(4.2)。当我将我的头像从'me.jpg'更新为'you.jpg'时,终端会抛出错误ActionController::RoutingError (No route matches [GET] "/system/users/avatars/000/000/010/original/me.jpg")
虚拟形象上传然而它不会像它应该的那样加载。我在我的顶栏中有一个恒定的current_user图像,当我从me.jpg更新到you.jpg时,图像变成了一个代表它未找到的图标。一旦我重新加载页面,图像就会出现。
完整错误
ActionController::RoutingError (No route matches [GET] "/system/users/avatars/000/000/010/original/me.jpg"):
actionpack (4.1.6) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.1.6) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.1.6) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.1.6) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.1.6) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.1.6) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.1.6) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.1.6) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.1.6) lib/rails/engine.rb:514:in `call'
railties (4.1.6) lib/rails/application.rb:144:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
/Users/calligouser/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
/Users/calligouser/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
/Users/calligouser/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
Rendered /Users/calligouser/.rvm/gems/ruby-2.1.1/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.6ms)
Rendered /Users/calligouser/.rvm/gems/ruby-2.1.1/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/routes/_route.html.erb (5.7ms)
Rendered /Users/calligouser/.rvm/gems/ruby-2.1.1/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/routes/_table.html.erb (5.4ms)
Rendered /Users/calligouser/.rvm/gems/ruby-2.1.1/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (56.9ms)
验证
has_attached_file :avatar, :default_url => "default_pic_male.png"
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
表格
<div class="sub-content">
<div class="field-row">
<%= f.label :avatar, "Avatar" %>
<%= f.file_field :avatar %>
</div>
<div class="field-row">
<%= f.label :first_name, "First Name*" %>
<%= f.text_field :first_name, { placeholder: "Name" } %>
</div>
<div class="field-row">
<%= f.label :last_name, "Last Name*" %>
<%= f.text_field :last_name, { placeholder: "Name" } %>
</div>
<div class="field-row">
<%= f.label :email, "Email*" %>
<%= f.email_field :email, { placeholder: "Email" } %>
</div>
<div class="field-row">
<%= f.label :gender, "Gender*" %>
<%= f.select :gender, User::GENDERS %>
</div>
<div class="field-row">
<%= f.label :password, 'Password (min 8 chars)' %>
<%= f.password_field :password, { placeholder: "Password" } %>
</div>
<div class="field-row">
<%= f.label :password_confirmation, "Password Confirmation" %>
<%= f.password_field :password_confirmation, { placeholder: "Password Confirmation" } %>
</div>
</div>
<footer>
<%= f.submit class: 'button right' %>
</footer>
修改视图
<div class="content-wrap">
<div class="column half">
<section class="full">
<header>
<ul>
<li><h3>Edit</h3></li>
</ul>
</header>
<%= form_for @user, :html => { :multipart => true } do |f| %>
<%= render 'form', f: f %>
<% end %>
</section>
</div>
</div>
注意:我没有手动设置回形针的任何路径。从我看到的,当我上传'you.jpg'时,它上传它并替换'me.jpg',然后在终端抱怨我想,因为它试图找到'me.jpg'仍然?为什么,我不知道,我不确定这是不是问题。任何帮助将不胜感激,谢谢。