我有一个网络应用程序,要求用户更新图像。我已经使用Paperclip gem安装了它。这适用于本地主机。但是在Heroku上,它确实上传了图像,但是当他们单击“后退”按钮查看listings.index文件时,出现“内部服务器错误”。
20: <tr>
2014-07-21T16:18:42.727180+00:00 app[web.1]: Completed 500 Internal Server Error in 390ms
2014-07-21T16:18:42.726840+00:00 app[web.1]: Rendered listings/index.html.erb within layouts/application (383.4ms)
2014-07-21T16:18:42.729352+00:00 app[web.1]: 18: <tbody>
2014-07-21T16:18:42.729353+00:00 app[web.1]: 19: <% @listings.each do |listing| %>
2014-07-21T16:18:42.726897+00:00 app[web.1]: Rendered listings/index.html.erb within layouts/application (383.4ms)
2014-07-21T16:18:42.727145+00:00 app[web.1]: Completed 500 Internal Server Error in 390ms
2014-07-21T16:18:42.729361+00:00 app[web.1]: 24: <td><%= listing.price %></td>
2014-07-21T16:18:42.729366+00:00 app[web.1]:
2014-07-21T16:18:42.729418+00:00 app[web.1]: 21: <td><%= image_tag listing.image.url(:small) %></td>
2014-07-21T16:18:42.729422+00:00 app[web.1]: 24: <td><%= listing.price %></td>
2014-07-21T16:18:42.729410+00:00 app[web.1]: ActionView::Template::Error (Path '/small/1_mangos.jpg' not found):
2014-07-21T16:18:42.729365+00:00 app[web.1]: app/views/listings/index.html.erb:19:in `_app_views_listings_index_html_erb___3465202124191925527_69930398073120'
2014-07-21T16:18:42.729360+00:00 app[web.1]: 23: <td><%= listing.description %></td>
2014-07-21T16:18:42.729440+00:00 app[web.1]: app/views/l
istings/index.html.erb:19:in `_app_views_listings_index_html_erb___3465202124191925527_69930398073120'
2014-07-21T16:18:42.729357+00:00 app[web.1]: 21: <td><%= image_tag listing.image.url(:small) %></td>
listings.index.html.erb
<h3>Product Listings </h3>
<table class="table table-striped">
<thead>
<tr>
<th>Image</th>
<th>Name</th>
<th>Description</th>
<th>Price</th>
<th>Quantity</th>
<th>Company</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<% @listings.each do |listing| %>
<tr>
<td><%= image_tag listing.image.url(:small) %></td>
<td><%= listing.name %></td>
<td><%= listing.description %></td>
<td><%= listing.price %></td>
<td><%= listing.quantity %></td>
<td><%= listing.company %></td>
<td><%= link_to 'Show', listing, class: "btn btn-link" %></td>
<td><%= link_to 'Edit', edit_listing_path(listing), class: "btn btn-link" %></td>
<td><%= link_to 'Destroy', listing, method: :delete, data: { confirm: 'Are you sure?' }, class: "btn btn-link" %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Product Listing', new_listing_path, class: "btn btn-primary" %>
show.html.erb
<p id="notice"><%= notice %></p>
<div class="row">
<div class="col-md-6">
<div class="thumbnail">
<%= image_tag @listing.image.url %>
</div>
</div>
<div class="col-md-6">
<h3><%= @listing.name %></h3>
<p><%= @listing.price %></p>
<p><%= @listing.description %></p>
<p><%= @listing.quantity %></p>
<p><%= @listing.company %></p>
<%= link_to 'Edit', edit_listing_path(@listing), class: "btn btn-link" %> |
<%= link_to 'Back', listings_path, class: "btn btn-link" %>
宝石文件
来源' https://rubygems.org '
ruby "2.0.0"
gem 'rails', '4.0.4'
gem 'sass-rails', '~> 4.0.2'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'bootstrap-sass'
gem 'paperclip', github: 'thoughtbot/paperclip'
gem 'jbuilder', '~> 1.2'
gem "paperclip-dropbox", ">= 1.1.7"
gem "figaro"
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
group :production do
gem 'pg'
gem 'rails_12factor'
end
group :development, :test do
gem 'sqlite3'
end
at=info method=GET path="/" host=sincurudemo.herokuapp.com request_id=9c2482eb-dd09-42a0-80fc-905a729209dd fwd="185.30.24.132" dyno=web.1 connect=11 service=468 status=500 bytes=1090
2014-07-21T17:19:33.329057+00:00 app[web.1]: Rendered listings/index.html.erb within layouts/application (444.7ms)
2014-07-21T17:19:33.329212+00:00 app[web.1]: Completed 500 Internal Server Error in 446ms
2014-07-21T17:19:33.331035+00:00 app[web.1]:
2014-07-21T17:19:33.331056+00:00 app[web.1]: ActionView::Template::Error (Path '/small/1_mangos.jpg' not found):
2014-07-21T17:19:33.329050+00:00 app[web.1]: Rendered listings/index.html.erb within layouts/application (444.7ms)
2014-07-21T17:19:33.329199+00:00 app[web.1]: Completed 500 Internal Server Error in 446ms
2014-07-21T17:19:33.331061+00:00 app[web.1]: 20: <tr>
2014-07-21T17:19:33.331060+00:00 app[web.1]: 19: <% @listings.each do |listing| %>
2014-07-21T17:19:33.331063+00:00 app[web.1]: 22: <td><%= listing.name %></td>
2014-07-21T17:19:33.331066+00:00 app[web.1]: 24: <td><%= listing.price %></td>
2014-07-21T17:19:33.331067+00:00 app[web.1]: app/views/listings/index.html.erb:21:in `block in _app_views_listings_index_html_erb__108501327453821717_70092909422920'
2014-07-21T17:19:33.331070+00:00 app[web.1]:
2014-07-21T17:19:33.331077+00:00 app[web.1]:
2014-07-21T17:19:33.331079+00:00 app[web.1]: ActionView::Template::Error (Path '/small/1_mangos.jpg' not found):
2014-07-21T17:19:33.331058+00:00 app[web.1]: 18: <tbody>
2014-07-21T17:19:33.331080+00:00 app[web.1]: 18: <tbody>
2014-07-21T17:19:33.331081+00:00 app[web.1]: 19: <% @listings.each do |listing| %>
2014-07-21T17:19:33.331072+00:00 app[web.1]:
2014-07-21T17:19:33.331082+00:00 app[web.1]: 20: <tr>
2014-07-21T17:19:33.331062+00:00 app[web.1]: 21: <td><%= image_tag listing.image.url(:small) %></td>
2014-07-21T17:19:33.331065+00:00 app[web.1]: 23: <td><%= listing.description %></td>
2014-07-21T17:19:33.331069+00:00 app[web.1]: app/views/listings/index.html.erb:19:in `_app_views_listings_index_html_erb__108501327453821717_70092909422920'
2014-07-21T17:19:33.331083+00:00 app[web.1]: 21: <td><%= image_tag listing.image.url(:small) %></td>
2014-07-21T17:19:33.331085+00:00 app[web.1]: 23: <td><%= listing.description %></td>
2014-07-21T17:19:33.331087+00:00 app[web.1]: 24: <td><%= listing.price %></td>
2014-07-21T17:19:33.331089+00:00 app[web.1]: app/views/listings/index.html.erb:19:in `_app_views_listings_index_html_erb__108501327453821717_70092909422920'
2014-07-21T17:19:33.331084+00:00 app[web.1]: 22: <td><%= listing.name %></td>
2014-07-21T17:19:33.331088+00:00 app[web.1]: app/views/listings/index.html.erb:21:in `block in _app_views_listings_index_html_erb__108501327453821717_70092909422920'
listing.rb文件
class Listing < ActiveRecord::Base
if Rails.env.development?
has_attached_file :image, :styles => { :small => "50x", :thumb => "100x100>" }, :default_url => "default.jpg"
validates_attachment_content_type :image, :content_type => %w(image/jpeg image/jpg image/png)
else
has_attached_file :image, :styles => { :medium => "200x", :thumb => "100x100>" }, :default_url => "default.jpg",
:storage => :dropbox,
:dropbox_credentials => Rails.root.join("config/dropbox.yml"),
:path => ":style/:id_:filename"
end
validates_attachment_content_type :image, :content_type => %w(image/jpeg image/jpg image/png)
validates_attachment_presence :image
end
自Rails 3.2以来,在Heroku上的Rails 4应用程序中提供资产的行为已更改。
首先,启用服务静态资产production.rb
:config.serve_static_assets = true
。
然后,将rails_12factor gem添加到您的Gemfile
:gem 'rails_12factor', group: :production
同时,(每与OP的讨论),你没有:small
你的自定义键has_attached_file
用于Listing.rb
在非开发环境:
if Rails.env.development?
has_attached_file :image, :styles => { :small => "50x", :thumb => "100x100>" }, :default_url => "default.jpg"
validates_attachment_content_type :image, :content_type => %w(image/jpeg image/jpg image/png)
else
has_attached_file :image, :styles => { :medium => "200x", :thumb => "100x100>" }, :default_url => "default.jpg",
:storage => :dropbox,
:dropbox_credentials => Rails.root.join("config/dropbox.yml"),
:path => ":style/:id_:filename"
end
因此,一旦您:small => "50x"
在else
块中添加它就应该起作用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句