title: Rails - not letting model be updated if fields have certain values
body: <p>I have my Ticket model. And I have two select fields in addition to others. Now, on my Create action i have this:</p>
  
  <pre><code>if @ticket.user_id != 0 &amp;&amp; @ticket.team_id != 0
    flash[:alert] = "You cannot assign a ticket to both a team and a user!"
    render action: "new"
  else
    .... *execute update code normally*
  end
  </code></pre>
  
  <p>because i can't allow both of them to be different that 0, and this works well. </p>
  
  <p>however I have the same line on my Update action, and it still allows for both fields to be different than 0.</p>
  
  <p>Any ideas why? Or do you have another, better way of handling this?</p>
  
  <p>Here is my Controller: </p>
  
  <pre><code>class TicketsController &lt; ApplicationController
    before_filter :authenticate_user!
    def show
      @ticket = Ticket.find(params[:id])
      respond_to do |format|
        format.html # show.html.erb
        format.json { render json: @ticket }
      end
    end
    def new
      @ticket = Ticket.new
      respond_to do |format|
        format.html # new.html.erb
        format.json { render json: @ticket }
      end
    end
    def edit
      @ticket = Ticket.find(params[:id])
      @ticket.content = nil
      @ticket.whodidit = current_user.id
    end
    def create
      @ticket = Ticket.new(params[:ticket])
      @ticket.whodidit = current_user.id
      if @ticket.user_id != 0 &amp;&amp; @ticket.team_id != 0
        flash[:alert] = "You cannot assign a ticket to both a team and a user!"
        render action: "new"
      else
      respond_to do |format|
        if @ticket.save
          TicketMailer.ticket_creation(@ticket).deliver
          format.html { redirect_to @ticket, notice: 'Ticket was successfully created.' }
          format.json { render json: @ticket, status: :created, location: @ticket }
        else
          format.html { render action: "new" }
          format.json { render json: @ticket.errors, status: :unprocessable_entity }
        end
      end
      end
    end
    def update
      @ticket = Ticket.find(params[:id])
      if (params[:user_id] != 0 &amp;&amp; params[:team_id] != 0)
         flash[:alert] = "You cannot assign a ticket to both a team and a user!"
         render action: "edit"
      else
      respond_to do |format|
        if @ticket.update_attributes(params[:ticket])
          TicketMailer.ticket_update(@ticket).deliver
          format.html { redirect_to @ticket, notice: 'Ticket was successfully updated.' }
          format.json { head :no_content }
        else
          format.html { render action: "edit" }
          format.json { render json: @ticket.errors, status: :unprocessable_entity }
        end
      end
      end
    end
    def destroy
      @ticket = Ticket.find(params[:id])
      @ticket.destroy
      respond_to do |format|
        format.html { redirect_to tickets_url }
        format.json { head :no_content }
      end
    end
    def index
      @tickets = Ticket.paginate :page =&gt; params[:page], :per_page =&gt; 10, :order =&gt; 'id DESC'
    end
  end
  </code></pre>
  
  <p>Here is my model: </p>
  
  <pre><code>class Ticket &lt; ActiveRecord::Base
    belongs_to :department
    belongs_to :user
    belongs_to :team
    has_many :comments
    has_paper_trail
    attr_accessible :attachment, :subject, :content, :user_id, :department_id, :status, :priority, :shop_id, :order_id, :team_id, :whodunnit
    has_attached_file :attachment
    validates_attachment_content_type :attachment, {:content_type =&gt; %w(image/jpeg image/jpg image/png application/pdf application/msword application/vnd.openxmlformats-officedocument.wordprocessingml.document)}
    def self.receive_mail(message)
     id = message.subject[/(\d+)$/, 1]
     if id.present? &amp;&amp; Ticket.exists?(id)
       Ticket.update(id, content: message.body.decoded, user_id:11)
     else
       Ticket.create subject: message.subject, content: message.body.decoded, department_id: 2, :incoming_email =&gt; message.from.first
     end
   end
  end
  </code></pre>