diff --git a/README.mkd b/README.mkd index dddd3a4198..162b19e1cb 100644 --- a/README.mkd +++ b/README.mkd @@ -30,6 +30,15 @@ Help If you have a question, you can ask the [official RailsAdmin mailing list](http://groups.google.com/group/rails_admin) or ping sferik on IRC in [#railsadmin on irc.freenode.net](http://webchat.freenode.net/?channels=railsadmin). +API Update Note +--------------- +The ability to set model labels for each section (list, navigation, update, ...) has been removed, +as it was deemed unnecessarily granular and was not fully honored in all displays. +That also means that the methods `label_for_navigation`, etc. are no longer functional. They print a warning at the moment. +See details in the examples below for the currently supported way to label models. +This change was motivated by the conversation following a [bug report](https://github.com/sferik/rails_admin/issues/319/#issue/319/comment/875868) +about label display errors. + Screenshots ----------- ![List view](https://github.com/sferik/rails_admin/raw/master/screenshots/list.png "List view") @@ -78,6 +87,7 @@ configuration DSL which allows you to customize many aspects of the interface. The configuration code should be placed in an initializer file, for example: config/initializers/rails_admin.rb + ### General You can customize authentication by providing a custom block for `RailsAdmin.authenticate_with`. @@ -91,6 +101,58 @@ You can exclude models from RailsAdmin by appending those models to `excluded_mo config.excluded_models << ClassName end + +### Model Class and Instance Labels ### + +**Setting the model's label** + +If you need to customize the label of the model, use: + + RailsAdmin.config do |config| + config.model Team do + label "List of teams" + end + end + +This label will be used anywhere the model name is shown, e.g. on the navigation tabs, +Dashboard page, list pages, etc. + +**The object_label method** + +The model configuration has another option `object_label` which configures +the title display of a single database record, i.e. an instance of a model. + +By default it tries to call "name" or "title" methods on the record in question. If the object responds to neither, +then the label will be constructed from the model's classname appended with its +database identifier. You can add label methods (or replace the default [:name, :title]) with: + + RailsAdmin.config {|c| c.label_methods << :description} + +This `object_label` value is used in a number of places in RailsAdmin--for instance as the +output of belongs to associations in the listing views of related models, as +the option labels of the relational fields' input widgets in the edit views of +related models and as part of the audit information stored in the history +records--so keep in mind that this configuration option has widespread +effects. + + RailsAdmin.config do |config| + config.model Team do + object_label do + "#{bindings[:object].name} - #{bindings[:object].league.name}" + end + end + end + +This would output "Team's name - Team's league's name" in all the places +mentioned in paragraph above example. + +*Difference between `label` and `object_label`* + +`label` and `object_label` are both model configuration options. `label` is used +whenever Rails Admin refers to a model class, while `object_label` is used whenever +Rails Admin refers to an instance of a model class (representing a single database record). + + ### Navigation ### * hiding a model @@ -161,30 +223,6 @@ Both also accept a block: hide_in_navigation but that name is now deprecated - you should change your code to use hide_from_navigation. -**Setting the model's label** - -If you need to customize the label of the model within the navigation tab, use: - - RailsAdmin.config do |config| - config.model Team do - navigation do - label "List of teams" - end - end - end - -Remember, you can pass the value as an argument or as a block as with the -before mentioned visibility options. Besides that, the label also has a -shorthand syntax: - - RailsAdmin.config do |config| - config.model Team do - label_for_navigation "List of teams" - end - end - -which allows both forms of configuration value passing as well. - **To enable CKEditor for a field** Configure the model/field like so: @@ -216,7 +254,8 @@ tabs. Even though this option is not model specific, it shares the same semantics as the earlier ones - you could also pass in a block which would be evaluated at runtime. -### List view + +### List view ### * Number of items per page * Number of items per page per model @@ -230,7 +269,6 @@ evaluated at runtime. * Sortability * Column CSS class * Column width - * The object_label method **Number of items per page** @@ -456,37 +494,6 @@ column, you can: end end -**Fields - The object_label method** - -List section has a configuration option `object_label` which configures -the title of a single database record. - -By default it queries if the record in question has columns named "name" or -"title". If neither is found it returns the model's classname appended with its -database identifier. You can add label methods (or replace the default [:name, :title]) with: - - RailsAdmin.config {|c| c.label_methods << :description} - -This value is used in a number of places in RailsAdmin - for instance as the -output of belongs to associations in the listing views of related models, as -the option labels of the relational fields' input widgets in the edit views of -related models and as part of the audit information stored in the history -records - so keep in mind that this configuration option has widespread -effects. - - RailsAdmin.config do |config| - config.model Team do - list do - object_label do - "#{bindings[:object].name} - #{bindings[:object].league.name}" - end - end - end - end - -This would output "Team's name - Team's league's name" in all the places -mentioned in paragraph above example. - ### Create and update views * Field groupings diff --git a/app/controllers/rails_admin/history_controller.rb b/app/controllers/rails_admin/history_controller.rb index e643e835c4..a2ea8dd7de 100644 --- a/app/controllers/rails_admin/history_controller.rb +++ b/app/controllers/rails_admin/history_controller.rb @@ -24,7 +24,7 @@ def slider def for_model @page_type = @abstract_model.pretty_name.downcase - @page_name = t("admin.history.page_name", :name => @model_config.list.label) + @page_name = t("admin.history.page_name", :name => @model_config.label) @general = true @page_count, @history = AbstractHistory.history_for_model @abstract_model, params[:query], params[:sort], params[:sort_reverse], params[:all], params[:page] @@ -34,7 +34,7 @@ def for_model def for_object @page_type = @abstract_model.pretty_name.downcase - @page_name = t("admin.history.page_name", :name => @model_config.list.with(:object => @object).object_label) + @page_name = t("admin.history.page_name", :name => @model_config.with(:object => @object).object_label) @general = false @history = AbstractHistory.history_for_object @abstract_model, @object, params[:query], params[:sort], params[:sort_reverse] diff --git a/app/controllers/rails_admin/main_controller.rb b/app/controllers/rails_admin/main_controller.rb index 1284895547..8db9430eec 100644 --- a/app/controllers/rails_admin/main_controller.rb +++ b/app/controllers/rails_admin/main_controller.rb @@ -50,7 +50,7 @@ def new end @authorization_adapter.authorize(:new, @abstract_model, @object) end - @page_name = t("admin.actions.create").capitalize + " " + @model_config.create.label.downcase + @page_name = t("admin.actions.create").capitalize + " " + @model_config.label.downcase @page_type = @abstract_model.pretty_name.downcase render :layout => 'rails_admin/form' end @@ -66,11 +66,11 @@ def create end @object.attributes = @attributes @object.associations = params[:associations] - @page_name = t("admin.actions.create").capitalize + " " + @model_config.create.label.downcase + @page_name = t("admin.actions.create").capitalize + " " + @model_config.label.downcase @page_type = @abstract_model.pretty_name.downcase if @object.save - AbstractHistory.create_history_item("Created #{@model_config.list.with(:object => @object).object_label}", @object, @abstract_model, _current_user) + AbstractHistory.create_history_item("Created #{@model_config.with(:object => @object).object_label}", @object, @abstract_model, _current_user) redirect_to_on_success else render_error @@ -80,7 +80,7 @@ def create def edit @authorization_adapter.authorize(:edit, @abstract_model, @object) if @authorization_adapter - @page_name = t("admin.actions.update").capitalize + " " + @model_config.update.label.downcase + @page_name = t("admin.actions.update").capitalize + " " + @model_config.label.downcase @page_type = @abstract_model.pretty_name.downcase render :layout => 'rails_admin/form' @@ -92,7 +92,7 @@ def update @cached_assocations_hash = associations_hash @modified_assoc = [] - @page_name = t("admin.actions.update").capitalize + " " + @model_config.update.label.downcase + @page_name = t("admin.actions.update").capitalize + " " + @model_config.label.downcase @page_type = @abstract_model.pretty_name.downcase @old_object = @object.clone @@ -111,7 +111,7 @@ def update def delete @authorization_adapter.authorize(:delete, @abstract_model, @object) if @authorization_adapter - @page_name = t("admin.actions.delete").capitalize + " " + @model_config.list.label.downcase + @page_name = t("admin.actions.delete").capitalize + " " + @model_config.label.downcase @page_type = @abstract_model.pretty_name.downcase render :layout => 'rails_admin/delete' @@ -121,9 +121,9 @@ def destroy @authorization_adapter.authorize(:destroy, @abstract_model, @object) if @authorization_adapter @object = @object.destroy - flash[:notice] = t("admin.delete.flash_confirmation", :name => @model_config.list.label) + flash[:notice] = t("admin.delete.flash_confirmation", :name => @model_config.label) - AbstractHistory.create_history_item("Destroyed #{@model_config.list.with(:object => @object).object_label}", @object, @abstract_model, _current_user) + AbstractHistory.create_history_item("Destroyed #{@model_config.with(:object => @object).object_label}", @object, @abstract_model, _current_user) redirect_to rails_admin_list_path(:model_name => @abstract_model.to_param) end @@ -131,7 +131,7 @@ def destroy def bulk_delete @authorization_adapter.authorize(:bulk_delete, @abstract_model) if @authorization_adapter - @page_name = t("admin.actions.delete").capitalize + " " + @model_config.list.label.downcase + @page_name = t("admin.actions.delete").capitalize + " " + @model_config.label.downcase @page_type = @abstract_model.pretty_name.downcase render :layout => 'rails_admin/delete' @@ -144,7 +144,7 @@ def bulk_destroy @destroyed_objects = @abstract_model.destroy(params[:bulk_ids], scope) @destroyed_objects.each do |object| - message = "Destroyed #{@model_config.list.with(:object => object).object_label}" + message = "Destroyed #{@model_config.with(:object => object).object_label}" AbstractHistory.create_history_item(message, object, @abstract_model, _current_user) end @@ -241,7 +241,7 @@ def get_attributes def redirect_to_on_success param = @abstract_model.to_param - pretty_name = @model_config.update.label + pretty_name = @model_config.label action = params[:action] if params[:_add_another] @@ -258,7 +258,7 @@ def redirect_to_on_success def render_error whereto = :new action = params[:action] - flash.now[:error] = t("admin.flash.error", :name => @model_config.update.label, :action => t("admin.actions.#{action}d")) + flash.now[:error] = t("admin.flash.error", :name => @model_config.label, :action => t("admin.actions.#{action}d")) render whereto, :layout => 'rails_admin/form' end @@ -301,7 +301,7 @@ def list_entries(other = {}) @record_count = @abstract_model.count(options, scope) @page_type = @abstract_model.pretty_name.downcase - @page_name = t("admin.list.select", :name => @model_config.list.label.downcase) + @page_name = t("admin.list.select", :name => @model_config.label.downcase) end def associations_hash diff --git a/app/views/layouts/rails_admin/delete.html.erb b/app/views/layouts/rails_admin/delete.html.erb index 20a0c5319e..b8896a5734 100644 --- a/app/views/layouts/rails_admin/delete.html.erb +++ b/app/views/layouts/rails_admin/delete.html.erb @@ -20,7 +20,7 @@