# Changing model type

**URL:** <https://www.ruby-forum.com/t/changing-model-type/158793>\
**Category:** Rails\
**Created:** [January 28, 2009, 1:13am UTC](https://www.ruby-forum.com/t/changing-model-type/158793 "2009-01-28T01:13:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaredmoody](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/76d3ee/32.png) [@jaredmoody](https://www.ruby-forum.com/u/jaredmoody)\
**Post date:** [January 28, 2009, 1:13am UTC](https://www.ruby-forum.com/t/changing-model-type/158793/1 "2009-01-28T01:13:24Z")

</div>

I have a form that allows a User to add/edit the additional Users or  
LoginUsers to/on their account, but the wrong validations are run when  
updating a User to be a Login user or vice-versa.

For more clarity (with only one case shown):

class User \< ActiveRecord::Base  
end

class LoginUser \< User  
validates\_presence\_of :login  
validates\_presence\_of :password  
end

class UsersController \< ApplicationController  
…  
def update  
@user = @account.users.find(params[:id])

```
# revoking login privledges
if @user.is_a?(LoginUser) && !params[:allow_login]
  #switch the type here, tried a few different things but none work
  @user[:type] = "User"
end

if @user.update_attributes(params[:user])
  flash[:notice] = 'User successfully updated.'
  redirect_to(edit_account_path)
else
  # edit action rendered with errors on login and password
  render :action => "edit"
end

```

end  
…  
end

Can someone help me solve this?

Thanks!

---

<div class="post-metadata">

**Author:** ![jaredmoody](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/76d3ee/32.png) [@jaredmoody](https://www.ruby-forum.com/u/jaredmoody)\
**Post date:** [January 28, 2009, 3:22am UTC](https://www.ruby-forum.com/t/changing-model-type/158793/2 "2009-01-28T03:22:20Z")

</div>

Jared Moody wrote:

> I have a form that allows a User to add/edit the additional Users or  
> LoginUsers to/on their account, but the wrong validations are run when  
> updating a User to be a Login user or vice-versa.  
> …  
> # revoking login privledges  
> if @user.is\_a?(LoginUser) && !params[:allow\_login]  
> #switch the type here, tried a few different things but none work  
> @user[:type] = “User”  
> @user.save\_without\_validation!  
> @user = User.find(@user.id)  
> end

Try adding the above two lines.

–  
Rails Wheels - Find Plugins, List & Sell Plugins -  
[http://railswheels.com](http://railswheels.com)
