# Cant save a record project-user-role

**URL:** <https://www.ruby-forum.com/t/cant-save-a-record-project-user-role/150008>\
**Category:** Rails\
**Created:** [October 2, 2008, 10:29am UTC](https://www.ruby-forum.com/t/cant-save-a-record-project-user-role/150008 "2008-10-02T10:29:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mau](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ac8455/32.png) [@Mau](https://www.ruby-forum.com/u/Mau)\
**Post date:** [October 2, 2008, 10:29am UTC](https://www.ruby-forum.com/t/cant-save-a-record-project-user-role/150008/1 "2008-10-02T10:29:07Z")

</div>

I have a two models Projects and users. I have a many to many  
relation. Means that all users can be in a project and a user van be  
in many porjects. A user can be a Member, Admin. i created the  
relation table as projects\_users and added a role\_id. For this i  
created a view that list the users in the project in check boxes, so  
if you check the box it became an admin, so i pass an array, but when  
i save i sends an ActiveRecord::ReadOnlyRecord error.

def updaterole

```
    @project = Project.find(params[:id])
    if 1 == 1
             @test = @project.users.find(params[:user_ids])

           for resource in @test

             resource.role_id = 2
             resource.save # here is the error
           end
          flash[:notice] = 'Succeed.'
          redirect_to :action => 'resources', :id => @project
    else

          render :action => 'add'
    end

 end
```
