根据某些条件动态“named_scope”
亲爱的大家,我有一个 Student
模型,我在其中指定了一些 name_scope
,例如 from_program
、from_year
、from_school
、has_status
、from_course
等...
无论如何我都可以将不同的named_scope
链接在一起在运行时动态地取决于某些标准?
例如,如果访问数据的用户来自 Finance,我希望能够仅将 from_school
和 has_status
链接在一起。如果用户是讲师,我希望能够将 from_course
、from_school
链接在一起,依此类推...
我应该使用 named_scope
?或者我应该回到指定条件的好旧方式?
提前感谢您的建议! =)顺便说一句,我正在使用 Rails 2.3
dear all, i have a Student
model that i've specified some name_scope
in it, e.g. from_program
, from_year
, from_school
, has_status
, from_course
, etc...
is there anyway that i can chain the different named_scope
together dynamically depending on certain criterias during runtime?
for example, if the user accessing the data is from Finance, i want to be able to chain from_school
and has_status
together only. if the user is the lecturer, i want to be able to chain from_course
, from_school
together, and so on...
should i use named_scope
? or should i just fall back to the good old way of specifying conditions?
thanks for your suggestions in advance! =) btw i'm using rails 2.3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定我是否理解,但我认为你可以做这样的事情:
或更一般
I'm not sure, if I understood, but I think you could do something like this:
or more general
你可以尝试这样的事情
你可以像这样调用
以同样的方式你可以传递参数
You can try something like this
You can call like this
In the same way you can pass parameters