【发布时间】:2015-10-24 16:35:56
【问题描述】:
我的应用程序的投票按钮有问题,但问题仅在生产中。投票按钮在开发中(本地)工作,但是当我部署应用程序时,投票按钮仍然无法响应。单击时,它什么也不做,heroku 服务器日志中没有消息或指示。事实上,服务器日志中没有任何内容显示点击了任何内容。我查看了我的“_vote.html.erb”部分代码,并没有发现任何问题。然而,我怀疑问题可能来自我在部分中实现的 glyphicon 引导组件。我尝试更改代码无济于事。还是同样的问题。这是“votes/vote.html.erb”部分的内容:
<% if bookmark.votes.find_by(user: current_user).nil? %>
<button type="button" class="btn btn-info btn-sm" aria-label="Left Align">
<%= link_to "Like-bookmark", topic_bookmark_votes_path(topic, bookmark), method: :post, class: "glyphicon glyphicon-star"%>
</button>
<% else %>
<button type="button" class="btn btn-info btn-sm" aria-label="Left Align">
<%= link_to "Unlike-bookmark", topic_bookmark_vote_path(topic, bookmark, bookmark.votes.find_by(user: current_user)), method: :delete, class: "glyphicon glyphicon-star-empty" %>
</button>
<% end %>
“_vote.html.erb”部分是从“_bookmark.html.erb”部分调用的,因此它可以为每个书签呈现投票功能。这是“bookmarks/bookmark.html.erb”部分的内容
`
<% if defined?(upvoted_bookmark) && current_user.bookmarks.include?(upvoted_bookmark) %>
<div class="panel panel-danger">
<div class="panel-heading">
<div class="caption">
<h5>Created by <%= upvoted_bookmark.topic.user.name || upvoted_bookmark.topic.user.email %> on <%= upvoted_bookmark.created_at %></h5>
<br>
</div>
<div id="bkmak_url">
<%= link_to upvoted_bookmark.url, topic_bookmark_path(upvoted_bookmark.topic, upvoted_bookmark) %>
</div>
<% if policy(Vote.new).create? %>
<%= render partial: "votes/vote", locals: {topic: upvoted_bookmark.topic, bookmark: upvoted_bookmark} %>
<br>
<% end %>
</div>
</div>
<% else %>
<div class="caption">
<h5>Created by <%= bookmark.topic.user.name || bookmark.topic.user.email %> on <%= bookmark.created_at %></h5> <br>
</div>
<div id="bkmak_url" class="btn btn-default btn-xs active">
<%= link_to bookmark.url, topic_bookmark_path(bookmark.topic, bookmark) %>
</div>
<% if policy(bookmark).destroy? %>
<div class="btn btn-primary btn-md active btn-block">
<%= link_to "delete bookmark", topic_bookmark_path(bookmark.topic, bookmark), method: :delete, data: { confirm: "Are you sure you want to delete this bookmark?" } %>
</div>
<% end %>
<% end %>
Like i said before, the issue is only in production. It works perfectly in development (locally). I ranheroku 运行 rake db:migrate` 以确保我的生产数据库架构设置正确。我在开发中运行 sqlite3,在生产中运行 progresql(我知道这并不总是可取的)。如果您需要任何进一步的代码,请告诉我,并提前感谢您的善意和周到的帮助。
更新:============================================== ====================
@Siguza,谢谢。不,我在服务器日志或控制台中没有任何 JS 错误。然而,最终对我有用的是改变 glyphicon 组件的实现,就像
<% if bookmark.votes.find_by(user: current_user).nil? %>
<div class="btn btn-info">
<%= link_to "Like-bookmark", topic_bookmark_votes_path(topic, bookmark), method: :post, class: "glyphicon glyphicon-star" %>
</div>
<% else %>
<div class="btn btn-warning">
<%= link_to "Unlike-bookmark", topic_bookmark_vote_path(topic, bookmark, bookmark.votes.find_by(user: current_user)), method: :delete, class: "glyphicon glyphicon-star-empty" %>
</div>
<% end %>
这样使投票按钮在生产中正常工作。
【问题讨论】:
-
你的浏览器控制台有JS错误吗?
标签: ruby-on-rails twitter-bootstrap heroku partial-views glyphicons