title: Does this method that changes an instance variable belong in my Rails controller or model?
body: <p>I have a basic "best practice" question about controllers and instance variables.</p>
  
  <p>Say you have an instance variable in anew or update action in a controller, is it ok to modify that instance variable via a private method in the controller?  Or should the method exist in the model?</p>
  
  <p>e.g. in this example below, I need to loop through the attributes of an instance variable, and add or remove something.  For example, if I am using nested attributes 3 layers deep and have to remove certain attributes, change them and then add them back in.  I know this may seem strange, but assume it is necessary. </p>
  
  <pre><code>def new
    @some_thing = SomeThing.new(:some_params)
    do_something_to_inst_var # method call
    @some_thing.save
  end
  
  private
  
  def do_something_to_inst_var
    @some_thing.addresses.each do |address|
      # modify it in some  way
    end
  end
  </code></pre>
  
  <p>Or is this bad practice?  Should this be a method in the model and should be called like:</p>
  
  <pre><code>@some_thing.do_something_to_inst_var
  </code></pre>
  
  <p>OR</p>
  
  <p>should we explicitly pass the instance variable to the method like:</p>
  
  <pre><code>def new
    @some_thing = SomeThing.new(:some_params)
    do_something_to_inst_var(@some_thing) # method call
    @some_thing.save
  end
  
  private
  
  def do_something_to_inst_var(some_thing)
    some_thing.addresses.each do |addresses|
      # modify it in some way
    end
  end
  </code></pre>
  
  <p>I'm looking for some clarity here, with an example if possible.  I'm still learning and trying to improve and I didn't find an answer by searching.</p>