field :field_name, {options}
- Actions that the field will appear
:actions => [:index]
- Define if the field will be in the advanced search
:advanced_search => {operator: :equal}
- Define if the field will be sortable
- Default Value: true
:sortable => true
- Define the type of the render that will be used to render the field. If the type passed as parameter to SimpleForm, as a type of Input. The only exception is the :partial parameter that is explained below.
Instead of rendereing a field, Carnival fill search for a partial with the field name. The following declaration inside AuthorsPresenter
field :custom_partial, actions: [:edit], as: :partial
Carnival will try to render the partial '_custom_partial.html.haml' inside /app/views/authors. To be more useful the following objects are available to the called partial:
- record: available to all partials, it represents de current record being displayed.
- f: when a new or edit action is being rendered, the 'f' object will contain the current form being rendered.
For a many to many relations you should just put the field name just like any other field, like
field :products,
:actions => [:show, :new, :edit]
###Parameters
- :show_as_list
-
This param list each associated record. It'll try to call a method to_label in each of the associated records, if the associated record does not have a to_\label method the method will be the to_s method.
field :products, :actions => [:show, :new, :edit], :show_as_list => true
-
- nested_form
- When set to true Carnival will render a nested form for the association
- nested_form_modes (Required in case nested_form is set to true)
- This field can have the values :new or :associate.
- :new allow you edit the associated model in the same form of the current model
- :associate it'll just allow you associate a related model.
- This field can have the values :new or :associate.
###Translations Carnival can use the default ActiveRecord model_name to show your many relation. If you need a different version for plural (you'll probably need one if you have a compound model name), you can specify the same key of ActiveRecord model name appending _plural to it, for ex: activerecord.models.user would have a activerecord.models.user_plural translation. If that key exists, Carnival will use it
For a one to one relation you have two ways to setup a field, one that is used for exhibition and the other for edition.
If you want to show a one to one relation you should name your field with 'related_model.related_field_name'.
field 'category.name',
:actions => [:show, :index]
If you want to edit a one to one relation you should name your field with the name of the relation.
field :category,
:actions => [:new, :edit]
class ProductPresenter < Carnival::BaseAdminPresenter
field 'category.name',
:actions => [:show, :index]
field :category,
:actions => [:new, :edit]
end