Permalink
Browse files

Remove references of ActiveRecord::Base#rails_admin

See #289
  • Loading branch information...
1 parent 6695e48 commit e98362065a184ed972ef05ed8b2e576cbc3a5df5 @bbenezech bbenezech committed Aug 16, 2011
Showing with 127 additions and 104 deletions.
  1. +127 −104 README.md
View
231 README.md
@@ -28,6 +28,35 @@ Supported ORMs:
<a name="notices">Notices</a>
--------
+
+Configuration with ActiveRecord::Base#rails_admin is not recommended anymore and should be
+considered as expermimental (development) until further notice. Unfortunately, implementation
+of this feature is thougher than imagined. Any help is welcome, as usual.
+Please remove any rails_admin configuration from your ActiveRecord model and put it inside an
+initializer (as shown in this documentation now). Use:
+
+ RailsAdmin.config do |config|
+
+ ...
+
+ config.model MyActiveRecordModel do
+ # MyActiveRecordModel configuration
+ end
+
+ ...
+
+ end
+
+Instead of:
+
+ class MyActiveRecordModel < ActiveRecord::Base
+ rails_admin do
+ # MyActiveRecordModel configuration
+ end
+ end
+
+Please refer to issue http://github.com/sferik/rails_admin/issues/289
+
The master branch currently targets Rails 3.1.
If you are updating from a Rails 3.0 application, you will no longer need to
@@ -185,19 +214,7 @@ RailsAdmin provides its out of the box administrative interface by inspecting yo
models and following some Rails conventions. For a more tailored experience, it also provides a
configuration DSL which allows you to customize many aspects of the interface.
-The configuration code should be placed within model classes, for example:
-
- app/models/team.rb
-
- class Team < ActiveRecord::Base
- rails_admin do
- label "List of teams"
- end
- end
-
-Configuration code that is not specific to any model, such as options listed in
-the following General section and later in Mass Assignment Operations, should
-be placed in an initializer file, for example:
+The configuration code should be placed in an initializer file, for example:
config/initializers/rails_admin.rb
@@ -274,8 +291,8 @@ sure that new models are not automatically added to RailsAdmin, e.g. because of
If you need to customize the label of the model, use:
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
label "List of teams"
end
end
@@ -301,8 +318,8 @@ related models and for part of the audit information stored in the history
records--so keep in mind that this configuration option has widespread
effects.
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
object_label_method do
:custom_label_method
end
@@ -333,16 +350,16 @@ as false:
By passing the value as an argument:
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
visible false
end
end
Or by passing a block that will be lazy evaluated each time the option is read:
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
visible { false }
end
end
@@ -357,14 +374,12 @@ you want to get the Team model's visibility, you use
**Create a navigation_label in navigation**
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
parent League
end
- end
- ...
- class Division < ActiveRecord::Base
- rails_admin do
+
+ config.model Team do
parent League
end
end
@@ -384,8 +399,8 @@ This can be easily achieved with the 'navigation_label' method of the parent mod
Added to previous example:
- class League < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model League do
navigation_label 'League related'
end
end
@@ -410,8 +425,8 @@ menu subset. (but parent will always be first inside his submenu).
Example:
- class League < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model League do
navigation_label 'League related'
weight -1
end
@@ -492,8 +507,8 @@ Belongs_to associations :
otherwise on the foreign_key (:team_id)
you can also specify a column on the targetted table (see example) (3)
- class Player < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Player do
list do
field :created_at do # (1)
sortable false
@@ -520,17 +535,17 @@ Belongs_to associations :
Default sort column is :id for ActiveRecord version
To change it:
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
sort_by :name
end
end
By default, dates and serial ids are reversed when first-sorted ('desc' instead of 'asc' in SQL).
If you want to reverse (or cancel it) the default sort order (first column click or the default sort column):
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
list do
field :id do
sort_reverse? false # will sort id increasing ('asc') first ones first (default is last ones first)
@@ -555,8 +570,8 @@ Belongs_to associations :
or on their label if label is not virtual (:name, :title, etc.)
you can also specify columns on the targetted table or the source table (see example) (4)
- class Player < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Player do
list do
field :created_at do # (1)
searchable false
@@ -596,8 +611,8 @@ You can independently deactivate querying (search) or filtering for each field w
Empty filters can be displayed in the list view:
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
list do
filters [:name, :division]
end
@@ -611,8 +626,8 @@ By default all fields are visible, but they are not presented in any particular
order. If you specifically declare fields, only defined fields will be visible
and they will be presented in the order defined:
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
list do
field :name
field :created_at
@@ -626,8 +641,8 @@ If you need to hide fields based on some logic on runtime (for instance
authorization to view field) you can pass a block for the `visible` option
(including its `hide` and `show` accessors):
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
list do
field :name
field :created_at
@@ -648,8 +663,8 @@ authorization scheme for which you can find a guide at the end of this file.
The header of a list view column can be changed with the familiar label method:
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
list do
field :name do
label "Title"
@@ -669,8 +684,8 @@ As in the previous example this would show only columns for fields "name" and
The field's output can be modified:
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
list do
field :name do
formatted_value do # used in form views
@@ -693,8 +708,8 @@ current record instance in key :object and the view instance in key :view.
Via :object we can access other columns' values and via :view we can access our
application's view helpers:
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
list do
field :name do
formatted_value do
@@ -713,8 +728,8 @@ but that could be written more verbosely as `bindings[:object].name`.
Fields of different date types (date, datetime, time, timestamp) have two extra
options to set the time formatting:
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
list do
field :name
field :created_at do
@@ -739,8 +754,8 @@ and [Rails I18n repository](https://github.com/svenfuchs/rails-i18n/tree/master/
By default each column has a CSS class set according to field's data type. You
can customize this by:
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
list do
field :name
field :created_at do
@@ -759,8 +774,8 @@ By default columns' widths are calculated from certain pre-defined,
data-type-specific pixel values. If you want to ensure a minimum width for a
column, you can:
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
list do
field :name do
column_width 200
@@ -793,8 +808,8 @@ form builder then provide an override for the edit view or independingly for the
create and update views. The argument is a symbol or string that is sent to the view
to process the form. This is handy for integrating things like the nested form builder (https://github.com/ryanb/nested_form) if you need to override a field's edit template.
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
edit do
form_builder :nested_form_for
field :name
@@ -804,8 +819,8 @@ to process the form. This is handy for integrating things like the nested form b
or independently
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
create do
form_builder :create_form_for
field :name
@@ -833,8 +848,8 @@ create and update views just replace `edit` with `create` or `update`.
Field groups can be hidden:
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
edit do
group :default do
hide
@@ -852,8 +867,8 @@ option which was mentioned in the beginning of the navigation section.
Field groups can be renamed:
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
edit do
group :default do
label "Team information"
@@ -868,8 +883,8 @@ This would render "Team information" instead of "Basic info" as the groups label
Field groups can have a set of instructions which is displayed under the label:
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
edit do
group :default do
label "Team information"
@@ -889,8 +904,8 @@ contain field configurations, but in edit views those configurations can
also be nested within group configurations. Below examples result an
equal configuration:
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
edit do
group :default do
label "Default group"
@@ -903,8 +918,8 @@ equal configuration:
end
end
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
edit do
group :default do
label "Default group"
@@ -946,8 +961,8 @@ hide and show accessors as the list view has.
The edit view's fields are rendered using partials. Each field type has its own
partial per default, but that can be overridden:
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
edit do
field :name do
edit_partial "my_awesome_partial"
@@ -969,8 +984,8 @@ The partial should be placed in your applications template folder, such as
One can also completely override the rendering logic:
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
edit do
field :name do
render do
@@ -1041,8 +1056,8 @@ field method provides second parameter which is field type as a symbol. For
instance, if we have a column that's a text column in the database, but we'd
like to have it as a string type we could accomplish that like this:
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
edit do
field :description, :string do
# configuration here
@@ -1054,8 +1069,8 @@ like to have it as a string type we could accomplish that like this:
If no configuration needs to take place the configuration block could have been
left out:
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
edit do
field :description, :string
end
@@ -1099,8 +1114,8 @@ If you have a reusable field you can define a custom class extending
Then you can use your custom class in a field:
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
edit do
field :name, :my_awesome_type do
# configuration here
@@ -1120,8 +1135,8 @@ examples if you want to use that mechanism.
Every field is accompanied by a hint/text help based on model's validations.
Everything can be overridden with `help`:
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
edit do
field :name
field :email do
@@ -1139,8 +1154,11 @@ Everything can be overridden with `help`:
# handling delete in your model, if needed. Replace all image occurences with your asset name.
attr_accessor :delete_image
before_save { self.image = nil if self.delete_image == '1' }
-
- rails_admin do
+ end
+
+
+ RailsAdmin.config do |config|
+ config.model Team do
edit do
field :image do
thumb_method :thumb # for images. Will default to full size image, which might break the layout
@@ -1149,7 +1167,10 @@ Everything can be overridden with `help`:
end
end
end
-
+
+
+
+
**Fields - Enum**
Fields of datatype string, integer, text can be rendered with select boxes. Auto-detected if object responds to `#{method_name}_enum`.
@@ -1162,8 +1183,10 @@ You can use `enum` to override any `enum_method` and give back a `FormOptionsHel
# should return any collection accepted by `FormOptionsHelper#options_for_select`
# See http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-options_for_select
end
-
- rails_admin do
+ end
+
+ RailsAdmin.config do |config|
+ config.model Team do
edit do
field :color
# defaults to
@@ -1178,8 +1201,8 @@ You can use `enum` to override any `enum_method` and give back a `FormOptionsHel
If you don't have any enumeration method in your model, this will work:
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
edit do
field :color, :enum do
enum do
@@ -1194,8 +1217,8 @@ If you don't have any enumeration method in your model, this will work:
CKEditor can be enabled on fields of type text:
- class MyModel < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
edit do
field :description, :text do
ckeditor true
@@ -1210,8 +1233,8 @@ Orderable can be enabled on filtering multiselect fields (has_many, has_many :th
allowing selected options to be moved up/down.
RailsAdmin will handle ordering in and out of the form.
- class Player < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Player do
edit do
field :fans do
orderable true
@@ -1249,8 +1272,8 @@ You can exclude specific fields with exclude_fields & exclude_fields_if:
Example:
- class League < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model League do
list do
exclude_fields_if do
type == :datetime
@@ -1267,8 +1290,8 @@ But you can then use include_all_fields to add all default fields:
Example:
- class League < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model League do
list do
field :name do
# snipped specific configuration for name attribute
@@ -1286,8 +1309,8 @@ It is also possible to add fields by group and configure them by group:
Example:
- class League < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model League do
list do
# all selected fields will be added, but you can't configure them.
# If you need to select them by type, see *fields_of_type*
@@ -1308,8 +1331,8 @@ Example:
Note that some fields are hidden by default (associations) and that you can display them to the list view by
manually setting them to visible:
- class League < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model League do
list do
field :teams do
visible true
@@ -1363,8 +1386,8 @@ configuration is only effective for create, list and update views.
Naturally this also works for a single model configuration:
- class Team < ActiveRecord::Base
- rails_admin do
+ RailsAdmin.config do |config|
+ config.model Team do
fields do
label do
label.upcase

0 comments on commit e983620

Please sign in to comment.