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 7058549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:07:33+00:00 2026-05-28T04:07:33+00:00

How do I make a drop down menu reflect what’s stored in it’s corresponding

  • 0

How do I make a drop down menu reflect what’s stored in it’s corresponding column in a database?

I have a dropdown menu for gender selection and it updates the database fine
but goes back to default option in select menu on refresh where as all my text fields are pulling db data fine.

<%= form_for @profile, :remote => true,  do |f| %>
Username: <%= @profile.user.username %><br />
URL: http://site.com/<%= @profile.user.username %><br />
First Name: <%= f.text_field :first_name,   %><br />
Last Name: <%= f.text_field :last_name,  %><br />
I am: <%= f.select :gender, options_for_select([['Select Gender', ''],['Male','m'],['Female','f']]) %><br />
<%= f.submit 'update' %><br />
<% end %>

Any clue what I’m missing?
Kind regards

Here’s my model:

class Profile < ActiveRecord::Base

  belongs_to :user

   attr_accessible :first_name, :last_name, :gender, :motd

  # Local Variables
  # Regex Variables
  email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
  alpha_regex = /^[a-zA-Z]*$/
  alpha_numeric_regix = /^[a-zA-Z0-9_]*$/


    #Form Validation
    validates :first_name,    :presence      => true,
                              :length        => { :minimum => 2, :maximum => 15 },
                              :format        => {
                                                  :with => alpha_regex,
                                                  :message => "Your first name must contain letters only"
                                                }

    validates :last_name,     :presence      => true,
                              :length        => { :minimum => 2, :maximum => 15 },
                              :format        => {  
                                                  :with => alpha_regex,
                                                  :message => "Your last name must contain letters only"
                                                }

    validates :gender,        :presence      => true,
                              :inclusion     => { 
                                                  :in => %w( m f ), :message => "Are you male or female?"
                                                }


end

Update method from controller

 def update

   respond_to do |format|

     if @profile.update_attributes(params[:profile])

       format.js   { render :js => "window.location = '#{settings_edit_profile_path}'" } 
       flash[:success] = "Profile updated" 
     else
      format.js   { render :form_errors }

    end
  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-28T04:07:34+00:00Added an answer on May 28, 2026 at 4:07 am

    options_for_select has a special syntax for selecting a value:

    <%= f.select :gender, options_for_select([['Select Gender', ''],['Male','m'],['Female','f']], "#{@profile.gender}") %>
    

    might work like you expect.

    Or you could create a Gender model and use collection_select which does this by default:

    <%= f.collection_select :gender, Gender.all, :value, :description, :prompt => true %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I make a drop down menu reflect what's stored in it's corresponding
I need to make tabs that also have drop down menu and requirements are
I'm trying to make a drop down menu using javascript/jquery but can't get my
I'm trying to find/make a good jquery drop-down menu with animation (fadein/fadeout or slidedown)
I am trying to make drop down menu. Some folks helped me on CSS
I am trying to make CSS drop down menu (no javascript involved). According to
I'm trying to make a basic drop down menu with animate and am running
I have a drop down menu with 3 values. each has an option id.
I am trying to make a drop down menu of links. I use the
I have a drop down menu which I found a tutorial for. In Firefox

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.