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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:40:11+00:00 2026-05-28T01:40:11+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 birthday selection and it updates the database fine
but goes back to default options in select menu on refresh where as all my text fields are pulling db data fine.

My form:

    <%= 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']], "#{@profile.gender if @profile.gender}") %><br />
My birthday: 
<%= f.select :day, options_for_select(Profile::DAYS), :include_blank => "Day" %>
<%= f.select :month, options_for_select(Profile::MONTHS), :include_blank => "Month" %>
<%= f.select :year, options_for_select(Profile::YEAR_RANGE), :include_blank =>"Year" %><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_accessor   :password, :day, :month, :year
   attr_accessible :first_name, :last_name, :gender, :motd, :day, :month, :year

  # 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_]*$/

  MONTHS = ["January", 1], ["February", 2], ["March", 3], ["April", 4], ["May", 5], ["June", 6], ["July", 7], ["August", 8], ["September", 9], ["October", 10], ["November", 11], ["December", 12]
  DAYS = ["01", 1], ["02", 2], ["03", 3], ["04", 4], ["05", 5], ["06", 6], ["07", 7], ["08", 8], ["09", 9], ["10", 10], ["11", 11], ["12", 12], ["13", 13], ["14", 14], ["15", 15], ["16", 16],
        ["17", 17], ["18", 18], ["19", 19], ["20", 20], ["21", 21], ["22", 22], ["23", 23], ["24", 24], ["25", 25], ["26", 26], ["27", 27], ["28", 28], ["29", 29], ["30", 30], ["31", 31]
  START_YEAR = Time.now.year - 111
  END_YEAR = Time.now.year
  YEAR_RANGE = START_YEAR..END_YEAR


    #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?"
                                                }



  before_save :prepare_birthday

validate :validate_birthday # if :birthday == nil


private
def prepare_birthday
  begin
    unless year.blank? # in order to avoid Year like 0000
      self.birthday = Date.new(self.year.to_i, self.month.to_i, self.day.to_i)
    end
      rescue ArgumentError
    false
  end
end

def validate_birthday
  errors.add(:birthday, "Birthday is invalid") unless prepare_birthday
end
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-28T01:40:11+00:00Added an answer on May 28, 2026 at 1:40 am

    You shouldnt do it that way thats not the way it should be. In rails you should use the date_select form helper. => http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-date_select When you use this helper it will automaticly work in creation and updating your objects!

    Another possibility would be to use the jQuerUI datepicker which is great too.

    • 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.