How can I specify available ActiveScaffold actions on a per-record basis?
-
18-04-2021 - |
質問
I have a very simple admin controller in my Rails 2 app that displays all the records for a model read-only:
class Admin::InspectionsController < ApplicationController
active_scaffold :inspections do |config|
[:create, :update, :delete].each {|a| config.actions.exclude a}
config.actions.exclude :nested
end
end
I wish to make these model objects editable, but only if they are in a certain state (ie, before they've been approved). I can do this for all Inspections
by removing :update from the exclusions list, but I don't want to enable editing wholesale.
Is there a way to specify conditional actions to ActiveScaffold?
解決
I think you are looking for this: https://github.com/activescaffold/active_scaffold/wiki/Security. Head down to 'Model Methods: Restricting Anything Else'
Long story short, you enable all actions, and then add methods to your model definition to toggle said actions for each record, as described in the link.
所属していません StackOverflow