The presenter implements some conditional methods to verify if a action or field must be displayed. If some additional information is needed, the following objects will be available on these render methods:
- current_user: the 'current_user' variable inside the controller context.
- @controller: the current controller of the application.
Before rendering a field, Carnival calls the '''.render_field?''' method on presenter. If this method returns a false value, the field wil not be displayed.
- field_name: name of the field that will be rendered.
- action_name: name of the controller action that is being executed ("index", "edit", "new" ...)
def render_field?(field, action)
return false if action == "show" and field.name == :surname
true
end
Before rendering an action, Carnival calls the '''.render_action?'''method on presenter. If this method returns a false value, the field wil not be displayed.
- record: the record that will be rendered
- record_action: name of the action that will be rendered.
- action_name: name of the controller action that is being executed ("index", "edit", "new" ...)
def render_action?(record, record_action, action)
return false if record_action == :edit
true
end
This feature is used when you have dependent selects like Country, State and City to fill an Address or a Location, because Cities Select only can be filled withe the oprions when a State is selected, and the State when de Country is selected, to implement this kind of behavior in a form, just use the option :depends_on in the dependent field with the symbol of the dependency, follows an example bellow:
field :country,
:actions => [:index, :csv, :new, :edit, :show]
field :state,
:actions => [:index, :csv, :new, :edit, :show]
:depends_on => :country
field :city,
:actions => [:index, :csv, :new, :edit, :show]
:depends_on => :state