移植条件哈希以在新的 Rails 3 活动记录查询接口中使用
我正在将 Rails 2.3.5 应用程序升级到 Rails 3。我没有实现该应用程序,我只是将其升级。我发现开发人员使用查询哈希的方式很难在不触及许多文件的情况下更改它,这是我想避免的。
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
有许多从 A 继承的类。我需要将 A 类中的查询转换为 Rails 3。有人可以建议将其移植到 Rails 3 的最佳方法,而不更改从 A 继承的类实现 Specific_params 方法。
谢谢。
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 need 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将在 Rails 3 中工作。
或者你可以将其更改为:
will work in Rails 3.
Or you could change it to where: