我有一个模型POSTS
。 因为我在这个模型中有两个作用域 active
,inactive
. 我想根据params[:active]
值PostsController
使用其中一个。 喜欢关注
if params[:active] == "true"
@posts = POSTS.where some_condition
.include some_thing
.active
.page
.per
else
@posts = POSTS.where some_condition
.include
.inactive
.page
.per
end
有没有更好的方法来做同样的事情?我尝试了很多方法。 但我做不到。帮帮我。谢谢
@posts = POSTS.where some_condition
.include some_thing
.public_send(params[:active] == "true" ? :active : :inactive)
.page
.per
Object#public_send
.