First of all, I've been learning Rails for 8 months but feel like I started yesterday, so please bear with me. I'm trying to resolve why my value, called visible, isn't functioning correctly. I'm using Simple_form. 'visible' is the radio button value:
<div class='review-form'>
<%= simple_form_for(@review) do |f| %>
# input boxes for current_user to put text here
#'public' radio button, checked by default, class is for css
<%= f.radio_button :visible, "true" , :class => "share_button" %>
#'private' radio button, class is for css
<%= f.radio_button :visible, "false", :class => "keep_private_button" %>
#user can cancel
<%= link_to I18n.t('write_review.cancel_button'), landing_page,
:class => 'btn' %>
#user can submit
<%= f.button :submit, I18n.t('write_review.submit_button'),
:class => 'btn btn-primary' %>
The idea is that the current_user writes a review - if they make it 'public', any other user can see it, if private, only they can see it. The radio buttons work ok - when I log out, look at the app on different machines etc, the radio button is in the last saved state. The problem is that the current review, @review, is always visible to everybody, regardless of the state of the radio button.
I put <%= @review.visible? %>
on the review form. Every time I refresh the page it is 'true', even though the radio button might be false. I save the review and @review.visible then matches accordingly. But then I refresh and it goes back to true.
I think the problem could be:
In my schema.rb I have:
t.boolean "visible", :default => true
I deleted :default => true
and there was no improvement but I hear you're not supposed to manually interfere with the schema.rb anyway.
Do you think that default => true is causing the problem? Would doing a 'migration' be the way to go? How would I word that 'default => true' part in the migration?
Finally, while my schema.rb has 'boolean' my actual database has visible: tinyint(1)
, which I thought was fishy, but I've read online they're in fact the same thing, so I don't think that's the problem - if you think differently, let me know.