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

  • Home
  • SEARCH
  • 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 7598061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:18:52+00:00 2026-05-30T22:18:52+00:00

I have read the documentation on this, and still i have no idea how

  • 0

I have read the documentation on this, and still i have no idea how to do this.

I have a column in the table for :free that is a boolean

true  = free
false = paid
nil   = both

I’m trying to capture this same logic in my form and i’m doing an absolutely terrible job… so far everything comes up as free

index.html.erb:

 <div class="field">
    <label class="radio">
      <%= radio_button_tag(:free, "free", :checked => true) %>
      Free
    </label>
    <label class="radio">
      <%= radio_button_tag(:free, "paid") %>
      Paid
    </label>
    <label class="radio">
      <%= radio_button_tag(:free, "both") %>
      Both
    </label>
  </div>

resources_controller.rb (I know this isnt ideal because its checking the params every single time (even if they enter in wrong info) but i’m not sure how else to check if i can save it without saving it. Also… I dont even know if i did params right but i am not sure how to check it either. when i do p params[:resources] it doesnt print it how id like it to. is there a good way to do this kind of thing in rails?

def create
    @resource = Resource.new(params[:resource])

    if params[:resource][:free] = "free"
      @resource[:free] = true
    elsif params[:resource][:free] = "both"
      @resource[:free] = nil
    else
      @resource[:free] = false
    end

    if @resource.save
      redirect_to root_url
    else
      render :action => :new
    end 
  end

resources_helper.rb

  def output_free
    if @resource.free = true
      "Free"
    elsif @resource.free = false
      "Paid"
    else
      "Both"
    end
  end
  • 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-30T22:18:53+00:00Added an answer on May 30, 2026 at 10:18 pm

    That’s fuzzy logic, true/false/null. Does exist in SQL, you could used that, but that’s magic you don’t want. Use an Enum and three states – way clearer.

    And use == to compare 🙂

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

Sidebar

Related Questions

I have read the documentation for this element but still fail to understand what
I have read the documentation on this and I think I understand. An AutoResetEvent
I have quickly read over the Microsoft Lambda Expression documentation. This kind of example
I have read documentation for functions such as values and define-values that return and
I have read the documentation for the CI Caching but still don't understand much
I have read the documentation that states that "given the type of the enum,
I have read through the documentation for Winsock2 on MSDN, but I still need
I've read the documentation and understand that this is to be expected: Scripts are
I have read the Django documentation (For reference, https://docs.djangoproject.com/en/1.3/intro/tutorial01/ ), but I'm still having
I have read the documentation, but I still don't understand which classloader I should

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.