背景レール出力は、私は私のレールのアプリでストーリーのためのモデルを持っている
正しくないです。モデルの部分の1つは、 "published"のブール値です。
作成フォームと編集フォームでは、ストーリーが公開されている場合は「オン」、公開されていない場合は「オフ」と表示されるトグルボタンがあります。このトグルは現在正しく動作しており、ストーリーを公開するかどうかを切り替えることができます。このトグルはそれに従ってデータベースを更新する。ショーページ
問題
私は、if文をやろうとしたが、それは正しく解決されていなかったので、私はちょうど出版され、変数のプリントアウトを行なったし、それは常にfalse」出力しますデータベースをチェックしても "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、私は出版された情報を印刷していたところで問題を抱えていました。私のコードに問題がどこにあるのかを示すコメントがあります。 –