在我的应用程序中,我有Pillar和Blog的模型。每个blog belongs_to都有一个pillar。我的pillars#show中有以下逻辑,以便在该支柱的show页面上显示属于某个支柱的博客:
def show
@blogs = Blog.where(pillars_id: @pillar.id).limit(6)
end然后,在show.html.erb页面上,我得到了以下内容:
<% if @blogs.count != 0 %>
<div class="row blue-stripe">
<div class="container">
<h2 class="text-center">Blogs about <%= @pillar.name %></h2>
<% @blogs.each do |blog| %>
<%= link_to blog_path(blog) do %>
<div class="card blog-card col-xs-6 col-md-3">
<%= image_tag blog.image.url, alt: blog.title %>
<h3><%= blog.title %></h3>
<p><%= blog.teaser %></p>
<p><em><%= link_to "Read More", blog_path(blog) %>...</em></p>
</div> <!-- card -->
<% end %> <!-- link -->
<% end %> <!-- blogs each -->
</div> <!-- container -->
</div> <!-- row -->
<% end %>这在本地非常有效,但是当我部署到Heroku时,整个部分都没有出现。
举个例子,我通过运行heroku run rails c确认了,实际上,有属于我正在研究的支柱的博客。例如,一个博客的记录如下:
博客负载(2.9ms)从“博客”的顺序中选择“博客”.*。“id”=>限制1美元[“限制”,1] =>#游览一所房子有点像进行第一次访问.“,user_id: 2,created_at:"2018-06-03 21:00:56",updated_at:"2018-06-03 21:00:56",image_file_name:”53600574_l_(剪裁).jpeg“,image_content_type:“image_file_size/jpeg”,image_file_size: 569841,image_updated_at:"2018-06-03 21:00:56",弹格:“6键到看房子”,link_text:“下载一张可打印的家庭旅游说明”,link_filename:“app/资产/图像/house_ Tour _NOTITes.pdf”,pillars_id: 3>
然而,当我去pillars/3时,博客的蓝色条纹(if @blogs.count的内部)不会出现。
谁能弄清楚localhost和Heroku之间发生了什么来制造这个小故障呢?
发布于 2018-07-07 05:16:26
您注意到,每个博客belongs_to都是一个支柱。您是否确保在博客模型中添加has_many :pillars (或has_one :pillar,取决于您的需要)?我可以看到这样一种情况:在开发中明确设置关系(通过种子或其他方式),这在生产中是行不通的。
https://stackoverflow.com/questions/51219549
复制相似问题