Forum: Ruby on Rails RoR completely ignoring a column when saving changes

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
500ce8112f28a8c0a5e17a1c2fc630a5?d=identicon&s=25 armstheykill (Guest)
on 2006-05-11 03:40
I have an action that needs to update two models/two tables in one shot,
and it works great, but ignores one column. Here is the action code:
(verify_id is irrelevant in this case)

  def edit
    @page_title = "Edit User"
    @page_active_3 = "active"
      @user = User.find(params[:id])
      @profile = @user.profile
      verify_id(, true)
        if @user.update_attributes(params[:user]) and
          flash[:notice] = 'User was successfully updated.'
          redirect_to :action => 'view', :id =>
          render :action => 'edit'
        flash[:notice] = 'Errors occurred when attempting to update,
contact admin or check production.log'
        redirect_to :action => 'view', :id =>
    else # if GET request
      @user = User.find(params[:id])
      @profile = @user.profile
      verify_id(, true)

here is the view code:

<%= error_messages_for 'user' %>
<%= error_messages_for 'profile' %>

<div class="div_form">
	<% if session[:admin] == 'yes' -%>
	<h2>Login Details</h2>

	<p><label for="user_admin">Administrator Access</label>
		<%= select 'user', 'admin', [ ['no', 'no'],
										 ['yes', 'yes'] ] %></p>
	<% end %>

	<h2>Personal Profile</h2>

	<p><label for="profile_first_name">First Name</label><br />
		<%= text_field 'profile', 'first_name', :class => 'text_medium' %></p>

	<p><label for="profile_last_name">Last Name</label><br />
		<%= text_field 'profile', 'last_name', :class => 'text_medium' %></p>

	<p><label for="profile_location">UY Location</label>
		<%= select 'profile', 'location', [ ['USA', 'USA'],
											['South Africa', 'South Africa'],
											['UK', 'UK'],
											['South America', 'South America'],
											['Europe', 'Europe'],
											['Asia', 'Asia'] ] %>

	<p><label for="profile_email">Email Address</label><br />
		<%= text_field 'profile', 'email', :class => 'text_medium' %></p>


I suspect it may be a model validation problem, but i've removed all
validations for the edit/update action, but here is the model

require "digest/sha1"

class User < ActiveRecord::Base

  # Validations
  validates_uniqueness_of       :login_name,
                                :message => 'has already been taken',
                                :on => :save, :on => :create
  validates_presence_of         :login_name, :password, :admin,
                                :message => 'is required',
                                :on => :save, :on => :create
  validates_associated          :profile,
                                :on => :save, :one => :create

  # Associations
  belongs_to                    :profile, :foreign_key => 'profile_id',
:dependent => true
  has_many                      :articles

  # Attributes
  attr_accessor                 :password
  attr_accessible               :login_name, :password

.... etc ....
500ce8112f28a8c0a5e17a1c2fc630a5?d=identicon&s=25 Andrew Or\ (armstheykill)
on 2006-05-11 03:43
I should obviously mention that RoR is ignoring the 'admin' column of
the 'user' table which should be either 'yes' or 'no' . the column is
formatted as a varchar(15) with a default of 'no'
This topic is locked and can not be replied to.