Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Help Please! Radio button displaying True or False.

I'm trying to display male or female when a user selects the radio button. However, its displaying true or false. How can I get it to display male or female on my user show page and not true or false. Thank you


<div class="form-group"> <%= f.radio_button :isfemale, true %> <%= f.label :isfemale, "Female" %> <%= f.radio_button :isfemale, false %> <%= f.label :isfemale, "Male" %> </div>


     <%= @user.isfemale %>


class AddIsfemaleToUsers < ActiveRecord::Migration def change add_column :users, :isfemale, :boolean, default: false end end

2 Answers

Vance Rivera
Vance Rivera
18,322 Points

Don't know much about the syntax or Ruby in general but I think if you simply use conditional statement inside your label tag that should do what you want. All you need is one label and a simple if statement. Here is a general example but I'm sure the syntax is completely wrong. Hope this helps.

<label> <%= if(@user.isfemale) { "Female"; } else { "Male" } </label>
Kang-Kyu Lee
Kang-Kyu Lee
52,045 Points

following Vance's answer, it may be

<label><% if @user.isfemale %>Female<% else %>Male<% end %></label>


<label><%= @user.isfemale ? "Female" : "Male" %></label>

Thank you both! That worked!