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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:51:16+00:00 2026-06-18T04:51:16+00:00

I have the following User model with a artist_attributes virtual attribute: class User <

  • 0

I have the following User model with a artist_attributes virtual attribute:

class User < ActiveRecord::Base
  attr_accessor :artist_attributes
  attr_accessible :artist_attributes

  belongs_to :artist
  accepts_nested_attributes_for :artist, update_only: true
end

Here is the artist model:

class Artist < ActiveRecord::Base
  has_one :user
end

The problem is that the virtual attribute is not being set. For example, here my user controller:

class Members::UsersController < Members::BaseController
  def update
    current_user.artist_attributes = params[:user].delete(:artist_attributes)
    p current_user.artist_attributes # => nil
    # ...
  end
end

And here is the form that is submitted:

<%= simple_form_for current_user, url: members_profile_path do |f| %>
  <%= f.simple_fields_for :artist do |ff| %>
    <%# ... %>
  <% end %>

  <%= f.submit "Edit profile", class: "btn btn-primary", disable_with: "Editing profile..." %>
<% end %>

Why isn’t the artist_attributes virtual attribute not being set? Is it because of the nested form?

Update

Here is the params hash after I submit the form:

Parameters: {
  "utf8"=>"✓",
  "authenticity_token"=>"XQI4y7x7CSjxUhdYvEv2bLEjitwCfXxeTBUU3+kYS4g=",
  "user"=> {
    "email"=>"youjiii@gmail.com",
    "forename"=>"You",
    "surname"=>"Jiii",
    "password"=>"[FILTERED]",
    "password_confirmation"=>"[FILTERED]",
    "artist_attributes" => {
      "bio"=>"NERVO is awesome!",
      "phone_number"=>"",
      "city"=>"",
      "country"=>"Afghanistan"
    }
  },
  "commit"=>"Edit profile"}
  • 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-18T04:51:17+00:00Added an answer on June 18, 2026 at 4:51 am

    Try this:

    Change

    current_user.artist_attributes = params[:user].delete(:artist_attributes)
    

    To

    if current_user.update_attributes(params[:user])
      # happy result
    end
    

    Nested attributes should be handled automatically by Rails. If you need a custom setter, define artist_attributes= and you should be good. I believe Rails 4 will support hash values in Postgresql. Meannwhile look here for Rails 3: http://travisjeffery.com/b/2012/02/using-postgress-hstore-with-rails/

    Edit

    According to your comment, I wouldn’t store it in a virtual attribute if the goal is simply to send it to your API.

    # Controller
    def update
      if User.update_artist(params[:user][:artist_attributes])
        # happy thoughts
      end
    end
    
    # User model
    def update_artist(artist_attributes)
      begin
        # API call
      rescue api exception
        log a message like "Couldn't update at this moment"   
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have the following models. The User Model: class User < ActiveRecord::Base attr_accessible
I have the following User model on my application (simplified) class User < ActiveRecord::Base
I have the following code for my user model: class User < ActiveRecord::Base has_secure_password
I have the following User model: class User < ActiveRecord::Base has_many :competences has_many :skills,
I have the following models: class Song < ActiveRecord::Base belongs_to :albums end class Album
I have the following simplified model: class User attr_accessible :password validates :password, :presence =>
I've got the following User model: class User < ActiveRecord::Base # Users table has
Suppose I have the following models: class User(models.Model): pass class A(models.Model): user = models.ForeignKey(User)
Lets say we have following models. class User(db.Model): username=db.StringProperty() avatar=db.ReferenceProperty() class User(db.Model): username=db.StringProperty() avatar=db.StringProperty()
I have the following model: class User: name = models.CharField( max_length = 200 )

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.