title: Error in changing fields of associative table in roles and mod_objects
body: <p>I am trying to realize roles system for accessing our software models. So I have two models and a binding model for these two.</p>
  
  <p>Role (id, name), ModObject (id, name), ModObjectsRoles (role_id, mod_object_id, canCreate, canRead, canUpdate, canDelete). The last four fields are boolean.</p>
  
  <p>Role model :</p>
  
  <pre><code>class Role &lt; ActiveRecord::Base
    acts_as_authorization_role
  
    has_many :mod_objects_roles
    has_many :mod_objects, :through =&gt; :mod_objects_roles
  
    def change_role_permissions(mod_object_id)
      @tmp = self.mod_objects_roles.find_by_mod_object_id(mod_object_id) #I get from mod_objects_roles table the row with mod_object_id=34
      @tmp.canUpdate = false #change value of 'canUpdate' field to false
      @tmp.save              # and save it
    end
  end
  </code></pre>
  
  <p>ModObject model :</p>
  
  <pre><code>class ModObject &lt; ActiveRecord::Base
    has_many :mod_objects_roles
    has_many :roles, :through =&gt; :mod_objects_roles
  end
  </code></pre>
  
  <p>And an associative, joining these two above, ModObjectsRole :</p>
  
  <pre><code>class ModObjectsRole &lt; ActiveRecord::Base
    belongs_to :mod_object
    belongs_to :role
  end
  </code></pre>
  
  <p>The problem is, when I am trying to change ModObjectsRole models canCreate, canRead, canUpdate, canDelete fields to true or false values, it gives me error. I tried several ways for 3 days or more now. I can not find how to do this.</p>
  
  <p>In RolesController I use this code :</p>
  
  <pre><code>class RolesController &lt; ApplicationController
    before_action :set_role, only: [:show, :edit, :update, :destroy]
  
    def update
      respond_to do |format|
        if @role.update(role_params)
          @role.change_role_permissions(34) # this is where I am trying to test
          format.html { redirect_to @role, notice: "Hi"}
          format.json { render :show, status: :ok, location: @role }
        else
          format.html { render :edit }
          format.json { render json: @role.errors, status: :unprocessable_entity }
        end
      end
    end
  </code></pre>
  
  <p>I used mod_object_id as 34 in controller above just for test, just let me learn how to do it and I will try to handle the rest for myself :</p>
  
  <p>This is the table version of ModObjectRole, table mod_objects_roles :</p>
  
  <pre><code>mod_object_id | role_id | canCreate | canRead | canUpdate | canDelete       
      34            1         TRUE      TRUE       TRUE       TRUE
      2             1         FALSE     FALSE      TRUE       TRUE
  </code></pre>
  
  <p>Please help me if anyone has experience with it.
  Thank you in advance...</p>
  
  <p>Update, the error I get is :</p>
  
  <pre><code>TypeError in RolesController#update
  
  nil is not a symbol
  
  Extracted source (around line #10):
  
  @tmp = self.mod_objects_roles.find_by_mod_object_id(mod_object_id) #I get from mod_objects_roles table the row with mod_object_id=34
  @tmp.canUpdate = false #change value of 'canUpdate' field to false
  @tmp.save              # and save it
    end
  end
  </code></pre>