2014-12-01 1 views
0

레일 클립 4 응용 프로그램에 클립 클립을 설치했습니다. 나는 대부분 아래에 열거 된 튜토리얼을 따라 갔다.레일 4 -> 이미지 파일 이름에 "% 3F1417409694"을 (를) 추가하는 클립 - 리소스로드 실패 원인

이 문제의 요점은 (그리고 제가 생각하는 문제의 주요 원인이다), 그러나 최종 생각

에서이 게시물의 하단에 요약되어 있습니다 당신이 내가 포함시킨 모든 것을보기를 갈망한다면. 이것은 내가 종이 클립

Gemfile

gem 'paperclip', github: 'thoughtbot/paperclip' 

Product.rb (모델)

class Product < ActiveRecord::Base 

has_attached_file :image, :styles => { :small => "150x150>" }, 
    :url => "/assets/products/:id/:style/:basename.:extension", 
    :path => ":rails_root/public/assets/products/:id/:style/:basename.:extension" 


do_not_validate_attachment_file_type :image 

end 

마이그레이션

class AddAttachmentImageToProducts < ActiveRecord::Migration 
    def self.up 
    change_table :products do |t| 
     t.attachment :image 
    end 
    end 

    def self.down 
    remove_attachment :products, :image 
    end 
end 
을 사용하여 이미지를 첨부 한 일이다 (새 제품의 제작에 사용되는 양식)개

제품/index.html.erb (제품 테이블)

<%- model_class = Product -%> 
<div class="page-header"> 
    <h1><%=t '.title', :default => model_class.model_name.human.pluralize.titleize %></h1> 
</div> 
<table class="table table-striped"> 
    <thead> 
    <tr> 
     <th><%= model_class.human_attribute_name(:image) %></th> 
     <th><%= model_class.human_attribute_name(:id) %></th> 
     <th><%= model_class.human_attribute_name(:name) %></th> 
     <th><%= model_class.human_attribute_name(:price) %></th> 
     <th><%= model_class.human_attribute_name(:category) %></th> 
     <th><%= model_class.human_attribute_name(:created_at) %></th> 
     <th><%=t '.actions', :default => t("helpers.actions") %></th> 
    </tr> 
    </thead> 
    <tbody> 
    <% @products.each do |product| %> 
     <tr> 
     <td> <%= image_tag product.image.url(:small) %></td> 
     <td><%= link_to product.id, product_path(product) %></td> 
     <td><%= product.name %></td> 
     <td><%= product.price %></td> 
... 
..... 

_form.html.erb

<%= form_for @product, :html => { :multipart => true } do |f| %> 
    <% if @product.errors.any? %> 
    <div id="error_expl" class="panel panel-danger"> 
     <div class="panel-heading"> 
     <h3 class="panel-title"><%= pluralize(@product.errors.count, "error") %> prohibited this product from being saved:</h3> 
     </div> 
     <div class="panel-body"> 
     <ul> 
     <% @product.errors.full_messages.each do |msg| %> 
      <li><%= msg %></li> 
     <% end %> 
     </ul> 
     </div> 
    </div> 
    <% end %> 

    <div class="control-group"> 
    <%= f.label :name, :class => 'control-label' %> 
    <div class="controls"> 
     <%= f.text_field :name, :class => 'form-control' %> 
    </div> 
    <%= error_span(@product[:name]) %> 
    </div> 
    <div class="field"> 
    <%= f.label :image %><br> 
    <%= f.file_field :image %> 
</div> 
... 
..... 

관찰

다음은 터미널에서받는 오류 코드입니다.

ActionController::RoutingError (No route matches [GET] "/products/4/small/pflogo.png%3F1417408937"): 
    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/tagg 

내 이미지 파일 이름의 끝에 % 3F1417408937이 왜 추가되는지 확실하지 않습니다. path I 모델에서 설정 한 어떤 식 으로든 올바르지 않습니다

이미지 파일이 진정으로 public/assets/products/pflogo.png

에 위치해 그래서, 내 생각은 :url하고 있다는 점이다.

  • 내 제품 페이지 (localhst:3000/products)에는 이미지에 빈 자리 표시자가 있습니다. 일반적인 '깨진 이미지'미리보기 이미지입니다. 크롬 개발자 도구를 통해 요소를 검사 할 때 다음이 표시됩니다.

    Uncaught TypeError : undefined is functionbootstrap.js? body = 1 : 3 (익명 함수) jquery.js? body = 1 : 3120 firejquery.js? body = 1 : 3232 self.fireWithjQuery.js? body = 1 : 3444 jQuery.extend.readyjquery.js? body = 1 : 3475 완료

    제품 : 115 GET .... : // localhost : 3000/assets /products/4/small/pflogo.png%3F1417409694 404 (찾을 수 없음) 제품 : 127 GET .... : // localhost : 3000/images/small/missing.png 404 (찾을 수 없음) 제품 : 223 GET .... : // localhost : 3000/assets/products/17/small/pflogo.(찾을 수 없음) % 3F1417340013 404

최종 생각 그래서

를 PNG로, 다시 우리는 종이 클립 내 이미지 파일 이름에 %3F1417409694을 추가하는 것을 알 수있다. 요소 검사를 사용하여 이것을 편집하면 올바른 결과가 생성되고 제품 페이지에서 이미지를 볼 수 있습니다.

+1

는 점을 감안 작동합니다 '% 3F1417409694' url은'? 1417409694'로 디코드됩니다. URL에 ID 또는 캐시 버스터를 추가하려고하는 것처럼 보입니다 ... 왜 Github의 최신 Paperclip을 사용해야하는지 말해 줄 수 있습니까? ? 대부분의 사람들은보다 안정된 버전을 원할 것입니다. –

답변

2

단지 보석 '클립', GitHub의 변경 :

보석에 보석 파일에 "클립"

를 'thoughtbot/클립'을 다시 번들 이미지를 추가 그것은

+1

그래, [이 호] (https://github.com/thoughtbot/paperclip/issues/1706)처럼 보입니다. –