Heroku我们很抱歉,但单页出了点问题

时间:2013-06-24 20:13:05

标签: ruby-on-rails ruby heroku

所以我试图部署和应用程序到heroku。一切正常,除了一页产生错误 我们很抱歉,但出了点问题。

这似乎是一个非常常见的问题,但我还没有找到任何解决方案。即使在尝试rake之后:db migrate我还没有让它工作。这里是相关页面的代码。

谢谢!

_discussion.html.erb

<% content_for :script do %>
    <%= javascript_include_tag 'hover_content' %>
<% end %>

<% @micropost = Micropost.new %>
<% @micropost.discussion_id = discussion.id %>

<li>
  <div class = "intro-bar"><span class = "intro"><%=discussion.intro %></span></div>
  <div class = "content-bar">
    <span class = "content"><%= discussion.content %></span>
  </div>
  <input type='button' id='hideshow' value='hide/show'>
    <div class = "buttons">
      <!--<div class = "vote-neg"><%= link_to "Break Up", signup_path,class: "btn btn-large btn-breakup" %></div>-->
      <!--<div class = "vote-plus"><%= link_to "Stay Together", signup_path,class: "btn btn-large btn-staytogether" %></div>-->
    </div>

</li>

<span class = "timestamp">
    Posted <%= time_ago_in_words(discussion.created_at) %> ago.
  </span>

            <% if signed_in? %>
                <div class = "row">
                  <aside class = "span4">
                    <section>
                      <%= form_for(@micropost) do |f| %>
                          <%= render 'shared/error_messages', object: f.object %>
                          <div class="field">
                            <%= f.text_area :content, placeholder: "Post a comment" %>
                          </div>
                          <%= f.hidden_field :discussion_id%>

                          <%= f.submit "Break Up", class: "btn btn-large btn-breakup",:name => "break_up" %>
                          <%= f.submit "Stay Together", class: "btn btn-large btn-staytogether", :name => "stay_together" %>
                              <% end %>
                              </section>
                              </aside>
                              </div>
                          <% end %>

<div class = "comments">
  <% discussion.microposts.each do |micropost| %>
      <div class = 'comment-box'>
      <li>
        <div class = "comment-pic"></div>
        <div class = "post-comment"><%= micropost.content%></div>
      </li>
      </div>
  <% end %>
</div>

heroku日志

2013-06-24T20:23:26.126695+00:00 app[web.1]: ActionView::Template::Error (hover_content.js isn't precompiled):
2013-06-24T20:23:26.126695+00:00 app[web.1]:     1: 
2013-06-24T20:23:26.126695+00:00 app[web.1]:     2: 
2013-06-24T20:23:26.126695+00:00 app[web.1]:     3: <% content_for :script do %>
2013-06-24T20:23:26.126695+00:00 app[web.1]:     4:     <%= javascript_include_tag 'hover_content' %>
2013-06-24T20:23:26.126695+00:00 app[web.1]:     5: <% end %>
2013-06-24T20:23:26.126695+00:00 app[web.1]:     6: 
2013-06-24T20:23:26.126695+00:00 app[web.1]:     7: <% @micropost = Micropost.new %>
2013-06-24T20:23:26.126695+00:00 app[web.1]:   app/views/discussions/_discussion.html.erb:4:in `block in _app_views_discussions__discussion_html_erb__4373186011715748050_22056420'
2013-06-24T20:23:26.126926+00:00 app[web.1]:   app/views/discussions/_discussion.html.erb:3:in `_app_views_discussions__discussion_html_erb__4373186011715748050_22056420'
2013-06-24T20:23:26.126926+00:00 app[web.1]:   app/views/discussions/index.html.erb:6:in `block in _app_views_discussions_index_html_erb__565682135676542669_24344900'
2013-06-24T20:23:26.126926+00:00 app[web.1]:   app/views/discussions/index.html.erb:4:in `each'
2013-06-24T20:23:26.126926+00:00 app[web.1]:   app/views/discussions/index.html.erb:4:in `_app_views_discussions_index_html_erb__565682135676542669_24344900'
2013-06-24T20:23:26.126926+00:00 app[web.1]: 
2013-06-24T20:23:26.126926+00:00 app[web.1]: 
2013-06-24T20:23:26.168750+00:00 heroku[router]: at=info method=GET path=/discussions host=stage-breakupornot.herokuapp.com fwd="74.92.136.101" dyno=web.1 connect=2ms service=196ms status=500 bytes=643

1 个答案:

答案 0 :(得分:0)

问题与提及的评论中的其他问题一样,即您的javascript资源未预编译。

解决方案不仅仅是确保你预先编译资产,这就像heroku在推送时所做的那样,所以你不必这样做。

问题在于你这样做:

<% content_for :script do %>
  <%= javascript_include_tag 'hover_content' %>
<% end %>

由于您直接引用hover_content而不是仅仅将其包含在application.js中,因此您必须告诉Rails您希望将其包含在资产预编译步骤中。

修改您的production.rb文件并添加以下行:

config.assets.precompile += %w( hover_content.js )

这将告诉rails除了自动编译和包含的application.js之外,你还要包含这个其他文件hover_content.js