在控制器中安全使用多個示波器。在控制器中安全使用多個示波器
在控制器中,我需要調用三個範圍之一。如何安全地做到這一點?
如果我發送參數scope=destroy_all
這將刪除所有條目。
方法控制器:
的範圍:
scope :ended, -> {where ("date(current_timestamp) - date(created_at) > ends_at")}
scope :active, -> {where ("date(current_timestamp) - date(created_at) < ends_at")}
在訪問量:
.btn-group
= link_to _('Ended Campaigns'), admin_campaigns_path(scope: :ended), class: 'btn btn-default'
= link_to _('Ob-going Campaigns'), admin_campaigns_path(scope: :active), class: 'btn btn-default'
= link_to _('All Campaigns'), admin_campaigns_path(scope: :all), class: 'btn btn-default'
不這樣做,我會做!它太不安全了,至少把before_filter設置爲僅允許'ended'或'active'作爲params [:scope]的可能值。 params [:scope] = nil除非['ended','active']。include?(params [:scope]) – arieljuod
@arieljuod我對before_filter不瞭解,你能解釋一下嗎? – user3458697
查看我的回答 – arieljuod