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