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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:50:20+00:00 2026-05-27T09:50:20+00:00

I have an User model who has_one :preference , but I would like to

  • 0

I have an User model who has_one :preference, but I would like to join the form to update the user and the form to update his preference, so in the user’s form, I added :

<% if !@user.new_record? %>
  <div class="field">
    <%= label_tag 'user_preference_quote_type', 'Type de citations' %><br />
    <%= text_field_tag 'user_preference_quote_type', @user.preference.quote_type %>
  </div>
  <div class="field">
    <%= label_tag 'user_preference_locale', 'Langage' %><br />
    <%= text_field_tag 'user_preference_locale', @user.preference.locale %>
  </div>
<% end %>

And in my controller :

  def update
    @user = User.find(params[:id])
    @user.preference.quote_type = params[:user_preference_quote_type]
    @user.preference.locale = params[:user_preference_locale]

    respond_to do |format|
      if @user.update_attributes(params[:user])
        format.html { redirect_to(@user, :notice => t('c.users.update')) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @user.errors, :status => :unprocessable_entity }
      end
    end
  end

But the preferences would not change, how can I do it ? And is there is better way to do it ?

  • 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-27T09:50:20+00:00Added an answer on May 27, 2026 at 9:50 am

    This is not a good way of doing that. You should use fields_for. It will make your form cleaner. By the way, what you’re doing in the controller is not working because you use update_attributes to update your model that makes your assigments useless. Using the above mentioned fields_for will help you to clean the controller too. But be careful because you surely will need accepts_nested_attributes_for in your model.

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

Sidebar

Related Questions

Given I have an Artifact model and a User model: I would like to
So I have a User model that :has_many other models like Documents, Videos, Posts
For instance, let's say I have a User model. Users have things like logins,
I have a user model and a profile model. user has_one :profile profile belongs_to
I have a user model on which I check to make sure that the
I have a user model that requires the user to change their password every
I have a User model and a Submission model. Each Submission has a ForeignKey
I have a User model, a Post model, and an Interest model. User has_many
I have a User model, and use an acts_as_authentic (from authlogic) on it. My
Hello I have a user model and a ratings model. Whenever a new user

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.