Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6100537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:23:53+00:00 2026-05-23T13:23:53+00:00

I’m having a lot of trouble getting a simple true/false to evaluate properly in

  • 0

I’m having a lot of trouble getting a simple true/false to evaluate properly in Rails. I have this in a helper:

 def should_we_ask_to_subscribe?
    if @user.email.blank?
      true
    elsif @user.subscriber == false
      true
    else
      false
    end
  end

I test for blank because the user object is created by omniauth and sometimes, as with Twitter, I don’t get an email. After the authorization is created, the user is directed to update their profile and add an email. If there’s no email, I make sure to present the option to subscribe because they can’t be subscribed. This is the view:

<% if should_we_ask_to_subscribe?  %>

    <div class="field"> 
      <%= f.check_box :subscriber %>
      <%= f.label :subscriber, "It's okay to send me the occassional email. I know I can unsubscribe at any time." %>
    </div>

  <% else %>

     <div class="field">
        You're subscribed to our email list.<br /> 
        <%= f.check_box :unsubscribe %>
        <%= f.label :unsubscribe, "Please unsubscribe me." %>
      </div>

  <% end %>

However, even when the subscribe boolean is set to f — say a user has entered an email, but not subscribed (or unsubscribed, which is the only way the boolean would be f) should_we_ask_to_subscribe? still evaluates to false. I’ve tried various permuations but am just not getting it.

Update

Okay, so it’s clear that the database is storing the boolean value as false, but rails is interpreting it as true and I can’t really get why. Following advice below with inspect, the log shows @user.subscriber = true even though in the console and in the database I get subscriber: false for that particular user.

Second Update

So I’ve written some unit tests and they all pass. In my logs, I notice the code is doing the following:

(0.4ms)  UPDATE "users" SET "subscriber" = 'f', "updated_at" = '2011-07-05 13:40:58.178186' WHERE "users"."id" = 47

and this is the code, in a method in my model, that does that:

self.update_attribute(:subscriber, false)   

When I look at the database, both through an SQLite view and the console, I see an f and u.subscriber => false, respectively. But, when I use logger.info "@user.subscriber = #{@user.subscriber.inspect}" to see how the view helper is interpreting it, I get: @user.subscriber = true in the log. So, I’m assuming the problem is with how I set false since it seems rails is interpreting any value in the subscriber column as true (except in the console, where it seems to be saying its false?).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:23:54+00:00Added an answer on May 23, 2026 at 1:23 pm

    Diagnose whether the value of subscriber is not nil (which is a false equivalent) or whether it is not any other value.

    Put this line in the should_we_ask_to_subscribe function:

    logger.info "@user.subscriber = #{@user.subscriber.inspect}"
    

    Is your subscriber attribute declared as boolean? The checkbox would send a value of “0” (a string), which will evaluate to true in ruby, but usually is magically translated to ‘false’, but only for boolean attributes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.