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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:29:25+00:00 2026-06-16T11:29:25+00:00

I’m trying to use a textfield as a place for users to edit their

  • 0

I’m trying to use a textfield as a place for users to edit their birthday as a date. With the example, i’m working on, no birthday exists yet. The birthday that i’m trying to add is 03/21/1986.

Here’s the controller method:

# PUT /contacts/1/edit
    # actually updates the users data
    def update_user

        @userProfile = User.find(params[:id])
        @userDetails = @userProfile.user_details

        respond_to do |format|

            if @userProfile.update_attributes(params[:user]) 

                format.html {
                    flash[:success] = "Information updated successfully"
                    redirect_to(edit_profile_path)
                }
            else 

                format.html {
                    flash[:error] = resource.errors.full_messages
                    render :edit
                }
            end
        end
    end

and here’s the model method. You can see i’m calling a validation method on :birthday to convert it to a date. Everything seems to work, but nothing saves to the database and i get no errors.

# validate the birthday format
  def birthday_is_date
    p 'BIRTHDAY = '
    p birthday_before_type_cast

    new_birthday = DateTime.strptime(birthday_before_type_cast, "%m/%d/%Y").to_date
    p new_birthday

    unless(Chronic.parse(new_birthday).nil?)
        errors.add(:birthday, "is invalid")
    end

    birthday = new_birthday
  end

Here’s the printout from my p statements in my model validation method

"BIRTHDAY = "
"03/21/1986"
1986-03-21 12:00:00 -0600

I’ve also just noticed that if i do a date of 10/10/1980, it works just fine, and if i do a date of 21/03/1986, i get an invalid date error.

EDIT
Here’s some more info that may help:

view:

<%= form_for(@userProfile, :url => {:controller => "contacts", :action => "update_user"}, :html => {:class => "form grid_6 edit_profile_form"}, :method => :put ) do |f| %>
...
<%= f.fields_for :user_details do |d| %>
<%= d.label :birthday, raw("Birthday <small>mm/dd/yyyy</small>") %>                         
<%= d.text_field :birthday %>
...
<% end %>

user model

class User < ActiveRecord::Base
 ...

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me, :username, :login, :home_phone, :cell_phone, :work_phone, :birthday, :home_address, :work_address, :position, :company, :user_details_attributes

  validates_presence_of :email

  has_one :user_details, :dependent => :destroy
  accepts_nested_attributes_for :user_details
end

user_details model

require 'chronic'

class UserDetails < ActiveRecord::Base
  belongs_to :user

  validate :birthday_is_date

  attr_accessible :first_name, :last_name, :home_phone, :cell_phone, :work_phone, :birthday, :home_address, :work_address, :position, :company
# validate the birthday format
      def birthday_is_date
        p 'BIRTHDAY = '
        p birthday_before_type_cast

        new_birthday = DateTime.strptime(birthday_before_type_cast, "%m/%d/%Y").to_date
        p new_birthday

        unless(Chronic.parse(new_birthday).nil?)
            errors.add(:birthday, "is invalid")
        end

        birthday = new_birthday
      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-06-16T11:29:26+00:00Added an answer on June 16, 2026 at 11:29 am

    I ended up using a virtual attribute and it seems to be working now.

    I added this to my model

    attr_accessible :birthday_string
    
    def birthday_string
        @birthday_string || birthday.strftime("%d-%m-%Y")
      end
    
      def birthday_string=(value)
        @birthday_string = value
        self.birthday = parse_birthday
      end
    
      private
    
      def birthday_is_date
        errors.add(:birthday_string, "is invalid") unless parse_birthday
      end
    
      def parse_birthday
        Chronic.parse(birthday_string)
      end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I am using JSon response to parse title,date content and thumbnail images and place
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.