Background
I have a model for stories in my rails app. One of the parts of the model is a boolean for "published".
On the creation and edit forms, I have a toggle button that shows "On" if the story is published and "Off" if it is not published. This toggle currently works correctly and I am able to toggle a story from being published or not published;; and this toggle updates the database accordingly.
The problem
On the show page I was trying to do an if statement but it wasn't resolving correctly, so I just did a print out of the published variable and it always prints out "false" even when checking the database it is set to "true".
The Code
<% @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 %>