title: Adding a validation error in a controller in Rails 4
body: <p>In a controller I have a code which isn't associated with the model directly:</p>
  
  <pre><code>def create
  
    var1 = get_some_post_param
    # check if var1 isn't nil -- how to add an error the model if it is?
  
    # some other code...
    @m = Model.new(field1: var1, field2: var2, field3: var3)
    if @m.save
      # ok
      #....
    else
      # error
      ...
    end
  end
  </code></pre>
  
  <p>How can I add a validation error to the model right after <code>var1 = get_some_post_param</code> if <code>var1</code> is nil?</p>