On Viernes, 4 de enero de 2013 13:29:35 emai relle escribió:
> Hi
> 
> I try to configure different behaviours in AS, based on whether the AS is
> nested or directly called. Assume bills should only be created in the
> nested view, but a direct AS should list any bill, without possiblity to
> "Create".
> 
> I constructed following code, inspired from the "Per Request Configuration"
> wiki page. See comments for behaviour.
> 
> class BillsController < ApplicationController
> 
>   before_filter :bf_nested
> 
>   def bf_nested
>     if nested?
>        # This works
>        active_scaffold_config.list.label="Nested"
> 
>        # This has no effect on what is seen on the application
>        active_scaffold_config.actions.exclude :search
>     else
>       # This works as well
>       active_scaffold_config.list.label="Not"
> 
>       # This seems to work but has no effect on the end output on the
> application
>       active_scaffold_config.actions.exclude :search, :create
> 
>       # This generates an error because create was excluded above. So I
> conclude the exclude command works at a certain point in time.
>       #active_scaffold_config.create.link.label="Foo"
>     end
>   end
> 

Exclude is removing action, so you cannot configure it, but links is already 
added. So really, excluding actions shouldn't be done in before_filter. You can 
override ignore methods in the controller so link is not displayed on nested. 
Create has a ignore method, so you can override it, search doesn't have a 
default ignore method, so you must set search.link.ignore_method and define it.

>   active_scaffold :bill do |conf|
> 
>     # The nested? generates the following error:
>     # "undefined method `nested?' for BillsController:Class"
>     if nested?
>     else
>     end
>  .....
> 
> 
> 
> Is there a way to directly code the nested? into the |conf| block?

No, it's not possible check nested on starting app, because nested? is a 
controller instance method, not class method.

> 
> Or is there a smarter way to get different configs for the same controller?
> 

authorized and ignore methods.

active_scaffold :bill do |conf|
  conf.search.link.ignore_method = :ignore_search?
  ...
end

def ignore_create?
  super || !nested?
end

def ignore_search?
  !nested?
end

-- 
You received this message because you are subscribed to the Google Groups 
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/activescaffold?hl=en.

Reply via email to