porting conditions hash to use in new rails 3 active record query interface
I am upgrading a Rails 2.3.5 app to Rails 3. I did not implemented the app, I am just upgrading it. I have found that the developer has used query hash in a way that it is difficult to change it without touching many files, which I want to avoid.
class A
def method_1
AnObject.find(:all, :conditions => {:param_1 => @param_1}.merge(specific_params))
end
def specific_params
raise NoMethodError, "Subclasses must implement this method", "specific_params"
end
end
class B < A
def specific_params
{param_B1 => false, param_B2 => true}
end
end
There are many classes which inherit from A. I 开发者_如何学Cneed to convert the query in class A to Rails 3. Could somebody please suggest the best way to to port this to Rails 3 without changing the classes which inherit from A implement specific_params method.
Thanks.
AnObject.find(:all, :conditions => {:param_1 => @param_1}.merge(specific_params))
will work in Rails 3.
Or you could change it to where:
AnObject.where({:param_1 => @param_1}.merge(specific_params))
精彩评论