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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:02:17+00:00 2026-06-08T07:02:17+00:00

Im seriously stuck on an issue where I have a User and Profile model.

  • 0

Im seriously stuck on an issue where I have a User and Profile model.
whatever I try it seems validations are not triggered for any of the Profile attributes

  • The profile model belongs to User. User has_one Profile
  • On registration form using fields_for to have some profile fields displayed ( gender, and city and country )
  • Whatever I tried, I’m unable to let validation work for gender and city ( the fields_for profile fields)

My form:

- title t(:title, :scope => :register)
%h1= yield(:title)

  = simple_form_for(resource, :as => resource_name, :html => { :class => 'form-horizontal' } , :validate => true , :url => registration_path(resource_name)) do |f|

    = f.input :username,                  :label  => t(:username)
    = f.input :email,                     :label  => t(:email),
                                          :hint   => t(:hint_email_visible)
    = f.input :password,                  :label  => t(:password), :require => true
    = f.input :password_confirmation,     :label  => t(:password_confirm)


    - resource.build_profile
    = f.fields_for :profile do |f|

      #div

        = f.hidden_field :form, :value => "signup"

        .clear

        = f.input :gender,                :collection => [['Male', 'male'], ['Female', 'female']],
                                          :as => :radio

    = f.input :city,
              :readonly => "readonly",
              :label => t(:city)

    .ruler

    = f.input :country,
              :label => "Your country",
              :collection => [DataCountry.where(:code => 155).first],
              :value => @city,
              :id => "country",
              :name => "country"

    .clear


    = f.button :submit, t(:submit, :scope => :register) + " »"

My User model has this:

  accepts_nested_attributes_for :profile

My Profile model with validations is like:

  validates_presence_of :gender
  validates_presence_of :city
  validates_presence_of :country

My PARAMS:

-- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
utf8: ✓
authenticity_token: <mytokenhere>
user: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
  invite_code: ''
  username: username
  email: ''
  password: ''
  password_confirmation: ''
  profile_attributes: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
    form: signup
    gender: male
    dob(3i): '9'
    dob(2i): '7'
    dob(1i): '1942'
    city: 'somevalue'
    country: 'somevalue'
commit: Register »
action: create
controller: registrations

Rails console does:

User.new


 => #<User id: nil, email: "", encrypted_password: "", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, password_salt: nil, confirmation_token: nil, confirmed_at: nil, confirmation_sent_at: nil, unconfirmed_email: nil, failed_attempts: 0, unlock_token: nil, locked_at: nil, authentication_token: nil, username: nil, is_blocked: nil, is_deleted: nil, role: nil, slug: nil, created_at: nil, updated_at: nil, last_seen: nil, credits: nil, invite_code: nil, is_moderated: nil, locale: nil, status: nil, login_token: nil> 

Profile.new

 => #<Profile id: nil, user_id: nil, gender: nil, country: nil, state: nil, city: nil, status: nil, counter_cache: nil> 

—
UPDATE 19 Jul ’12

I added the

    - @user.errors.full_messages.each do |message|
  = message
  .clear

To the form to see what exactly is happening and this throws the following list of errors:

Email can't be blank
Email can't be blank
Password can't be blank
Password can't be blank
Profile city can't be blank
Profile gender can't be blank
Profile is invalid
Username can't be blank
Password confirmation can't be blank 

So it seems the validation is checked….
But no error styling is applied! Also the profile is invalid???? Im not sure but does that refer to the

  • 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-08T07:02:18+00:00Added an answer on June 8, 2026 at 7:02 am

    Many hours spend trying to fix this now the solution is very simple based on suggestions in this topic I found out that instead of

    WRONG:

    - resource.build_profile
    

    CORRECT:

    - resource.build_profile unless resource.profile
    

    what this does is not clean the profile but uses the old one if its available… so not cleaning out all the errors! hope this helps someone in the future!

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

Sidebar

Related Questions

I have a profile model I use to supplement the built in User model.
I'm seriously stuck here with something obvious. I have an application that communicates with
I have a std::vector containing a handful of numbers, which are not in any
Seriously, it seems like every time I want to make my UI elements talk
i am seriously struggling to get my head around regex. I have a sring
I've got a small problem (and it's probably seriously nothing). I have a small
I'm new to python, and seriously need help! I have a number of errors
(Note: I have seen this question and it uses a cursor not an animation.)
I have a web site that built from the ground up, and im seriously
I have serious problem I can not pass my data to controller when the

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.