我有我的Rails应用程序的故事的典范。模型的其中一个部分是“已发布”的布尔值。
在创建和编辑表单上,我有一个切换按钮,如果故事发布则显示“开”,如果未发布则显示“关”。此切换功能目前正常工作,并且可以切换发布或未发布的故事;;并且该切换器相应地更新数据库。
问题
在节目页面我试图if语句做的,但它并没有解决正确,所以我只是做了一个打印出已发布的变量,它总是打印出“假“即使在检查数据库时它被设置为”true“。
守则
<% @title="Stories" %>
<p><strong><%= @story.heading %></strong></p>
<p><%= @story.body %></p>
<p>
<%= #!!!!!!!!!!!!!!!!Not working currently!!!!!!!!!!!!!
# if @story.published
# @publish_Notice = "This story has been made public."
# else
# @publish_Notice = "This story is private."
# end
# @publish_Notice
@story.published # Always prints out 'false' even when database shows 'true'
%>
</p>
<p>~ <%= @story.authorName %></p>
<p>Submitted: <%= @story.created_at.strftime("%B, %d %Y") %><br/>
<%=
@location = " "
if @story.locationCity == "" || @story.locationCity == " " || @story.locationCity.nil?
@location = " "
else
@location = "Near: " @story.locationCity + ", " + @story.locationState
end
%>
<%= @location %></p>
<% if (user_signed_in?) && (current_user == @story.user) %>
<%= link_to 'Edit', edit_story_path(@story) %> |
<%= link_to 'Delete', @story, method: :delete, data: { confirm: 'Are you sure?' } %> |
<% end %>
<%= link_to 'Back', stories_path %>
其中哪一行是你面临的问题? – uzaif
@uzaif,我在打印出版信息时遇到了问题。我在我的代码中注明了问题出在哪里。 –