ActiveRecord selection, modified by optional parameters
Some notes:


That's too much code for a controller method, it should be moved to the model.
The same name (@measurements) holds up to 4 different values. As a general rule, avoid variable rebinding: different values, different names.
More about how the filtering method could be written keeping it DRY: https://stackoverflow.com/a/4480285/188031


For example:

class Measurement &lt; ActiveRecord::Base
  def self.filter(attributes)
    attributes.select { |k, v| v.present? }.reduce(all) do |scope, (key, value)|
      case key.to_sym
      when :sensor_id
        scope.where(key =&gt; value)
      when :last, :last_per_sensor 
        scope.send(key, value)
      else
        scope
      end 
    end
  end
end


And in the controller simply: 

@measurements = Measurement.filter(params.slice(:sensor_id, :last, :last_per_sensor))