我的rails应用程序的一部分显示了博客帖子。索引博客页面在heroku中显示此错误:
2014-10-23T08:19:39.662420+00:00 app[web.1]: Completed 500 Internal Server Error in 55ms
2014-10-23T08:19:39.662025+00:00 app[web.1]: Rendered posts/_post.html.erb (26.6ms)
2014-10-23T08:19:39.604425+00:00 app[web.1]: Started GET "/posts" for 14.203.244.3 at 2014-10-23 08:19:39 +0000
2014-10-23T08:19:39.607283+00:00 app[web.1]: Processing by PostsController#index as HTML
2014-10-23T08:19:39.662204+00:00 app[web.1]: Rendered posts/index.html.haml within layouts/application (30.9ms)
2014-10-23T08:19:40.175104+00:00 app[web.1]: ** [Airbrake] Failure: Net::HTTPUnauthorized
2014-10-23T08:19:40.177411+00:00 app[web.1]:
2014-10-23T08:19:40.177423+00:00 app[web.1]: 25:
2014-10-23T08:19:40.177425+00:00 app[web.1]: app/views/posts/_post.html.erb:22:in `block in _app_views_posts__post_html_erb__2896285066252331072_70186208567180'
2014-10-23T08:19:40.177426+00:00 app[web.1]: app/views/posts/_post.html.erb:22:in `map'
2014-10-23T08:19:40.177421+00:00 app[web.1]: 23: </ul>
2014-10-23T08:19:40.177427+00:00 app[web.1]: app/views/posts/_post.html.erb:22:in `_app_views_posts__post_html_erb__2896285066252331072_70186208567180'
2014-10-23T08:19:40.177422+00:00 app[web.1]: 24: </div>
2014-10-23T08:19:40.177429+00:00 app[web.1]: app/views/posts/index.html.haml:8:in `_app_views_posts_index_html_haml___4113059566178405055_70186208452460'
2014-10-23T08:19:40.177418+00:00 app[web.1]: 21: <ul class="tags">
2014-10-23T08:19:40.177430+00:00 app[web.1]:
2014-10-23T08:19:40.177416+00:00 app[web.1]: 19:
2014-10-23T08:19:40.177431+00:00 app[web.1]:
2014-10-23T08:19:40.177414+00:00 app[web.1]: ActionView::Template::Error (No route matches {:tag=>""} missing required keys: [:tag]):
2014-10-23T08:19:40.177417+00:00 app[web.1]: 20: <div class="tags_wrapper">
2014-10-23T08:19:40.177420+00:00 app[web.1]: 22: <li><%= raw post.tags.map(&:name).map { |t| link_to t, tag_path(t)}.join(' ') %></li>
2014-10-23T08:19:40.178906+00:00 heroku[router]: at=info method=GET path="/posts" host=www.guidetobe.co.uk request_id=570f17d3-4f6b-4db0-9d13-da69bc1ff49b fwd="14.203.244.3" dyno=web.1 connect=1ms service=574ms status=500 bytes=1575
2014-10-23T08:19:40.980832+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=www.guidetobe.co.uk request_id=767bc8e9-11e7-445f-8f78-d44a8c22ff0c fwd="14.203.244.3" dyno=web.1 connect=3ms service=1ms status=200 bytes=241
posts.rb模型是:
class Post < ActiveRecord::Base
extend FriendlyId
friendly_id :title, use: :slugged
validates :title, presence: true
validates :body, presence: true
validates :author, presence: true
validates :published_on, presence: true
has_many :taggings
has_many :tags, through: :taggings
# Tagging
def self.tagged_with(name)
Tag.find_by_name!(name).posts
end
def self.tag_counts
Tag.select("tags.id, tags.name, count(taggings.tag_id) as count").
joins(:taggings).group("taggings.tag_id, tags.id, tags.name")
end
def tag_list
tags.map(&:name).join(", ")
end
def tag_list=(names)
self.tags = names.split(",").map do |n|
Tag.where(name: n.strip).first_or_create!
end
end
end
posts / index.html.haml是:
- content_for :head, auto_discovery_link_tag(:atom, posts_url(format: "atom"))
.preview_posts_wrapper
.blog_posts_left_column
%h1{style: 'font-size: 20px; color: #6a6a6a;'} My blog
.rss_icon
= link_to image_tag('feed-icon-28x28.png'), posts_url(format: 'atom')
= render @posts
.blog_posts_right_column
%h3{style: 'font-size: 16px; color: #6a6a6a;'} Tag Cloud
.tag_cloud_wrapper
- tag_cloud Post.tag_counts, %w[s m l] do |tag, css_class|
= link_to tag.name, tag_path(tag.name), class: css_class
博客页面在我的localhost中运行正常。我不确定为什么它不适用于heroku?