active_scaffold :book do |config|
config.actions.exclude :create if @n > 5
end
or maybe: config.actions.exclude << :create if @n > 5
Is there a way to apply a test to config.actions.exclude?
Thanks.
Thanks for the tip; I had overlooked this. However, a little
experimentation has shown that per-request-configuration works fine on
columns, eg:
active_scaffold_config.list.columns.exclude :title
but unfortunately has no effect on actions, eg:
active_scaffold_config.actions.exclude :create
The code executes without errors but doesn't give the result I'm
after. Relevant parts of my controller are:
- - - - -
include AuthenticatedSystem
before_filter :login_required
before_filter :update_table_config
active_scaffold :library_config do |config|
config.columns =
[:library_name, :barcode_prefix, :starting_barcode, :login_name]
config.create.columns.exclude :login_name
config.actions = [:list, :show, :create, :update, :delete]
config.label = "Library Information and Data"
end
def update_table_config
n = LibraryConfig.count(:conditions => ['login_name = (?)',
[current_user.login]])
if n>0
active_scaffold_config.actions.exclude :create
# < - - - this has no effect
active_scaffold_config.list.columns.exclude :barcode_prefix # <
- - - but this does
else
active_scaffold_config.actions.add :create
end
end
- - - - -
What I want to do is prevent a user who already has a row in the
database from creating a second one. I can enforce this with a
validation but would rather the :create action not be available in the
first place.
OK, I posted a little too quickly on this because it does work after
all, but not quite the way I expected. When
active_scaffold_config.actions.exclude :create is applied, the "Create
new" link still appears, but clicking it gives "Request Failed (code
500, Internal Error)". This gets the job done, but I would like to
override this error message with a custom one if possible. Any way to
do that?
Thanks.
That's what I was looking for! Thanks very much.
I'm experiencing the same problem where actions configured per-request
have no effect, only in my case it's persisting. I'm trying
active_scaffold_config.actions =
[:list, :show, :update, :delete, :field_search, :nested, :subform]
and
active_scaffold_config.actions.add :update, :delete
neither work
is there anything you did that made it work?
Yes, but I didn't think it applied to my case...
to do
if current_user.is_superuser
active_scaffold_config.actions =
[:list, :show, :update, :delete, :field_search, :nested, :subform]
else
active_scaffold_config.actions =
[:list, :show, :field_search, :nested]
end
I would have to define security methods for each of them?
On May 25, 12:25 am, "Lance Ivy" <l...@cainlevy.net> wrote:
> Hi Oliver, did you see my earlier message (May 22) about using the
> #{action}_authorized? methods?
>
On May 25, 11:58 am, "Lance Ivy" <l...@cainlevy.net> wrote:
> Oh, and there's nothing wrong with doing stuff like this to keep your code
> clean:
>
> def delete_authorized?
> current_user.is_superuser?
> end
>
> alias update_authorized? delete_authorized?
>
> On 5/25/07, Lance Ivy <l...@cainlevy.net> wrote:
>
>
>
> > Just the ones that change - :update, :delete. Not sure about :subform ...
>