Module: EasyAdmin::Concerns::InlineFieldEditing
- Extended by:
- ActiveSupport::Concern
- Included in:
- ResourcesController
- Defined in:
- app/controllers/easy_admin/concerns/inline_field_editing.rb
Overview
InlineFieldEditing concern handles inline field editing functionality Provides methods for editing individual fields without full form submission
Instance Method Summary collapse
-
#edit_field ⇒ Object
Field editing actions.
-
#suggest ⇒ Object
Get autocomplete suggestions for fields.
- #update_field ⇒ Object
Instance Method Details
#edit_field ⇒ Object
Field editing actions
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/controllers/easy_admin/concerns/inline_field_editing.rb', line 9 def edit_field @field_name = params[:field] @field_config = find_field_config_by_name_or_association(@field_name) unless @field_config render json: { error: "Field '#{@field_name}' not found" }, status: :not_found return end respond_to do |format| format.html { render template: 'easy_admin/resources/edit_field', layout: false } format.turbo_stream { render template: 'easy_admin/resources/edit_field' } end end |
#suggest ⇒ Object
Get autocomplete suggestions for fields
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/controllers/easy_admin/concerns/inline_field_editing.rb', line 51 def suggest # Try to find field by name first, then by association name field_config = @resource_class.fields_config.find { |f| f[:name].to_s == params[:field] } # If not found by field name, try to find by association name if !field_config field_config = @resource_class.fields_config.find { |f| f[:association].to_s == params[:field] } end unless field_config && field_config[:suggest] render json: { error: "Field not found or suggest not configured" }, status: :not_found return end search_term = params[:q].to_s.strip limit = field_config[:suggest][:limit] || 10 results = (field_config, search_term, limit) render json: { options: results } end |
#update_field ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/easy_admin/concerns/inline_field_editing.rb', line 24 def update_field @field_name = params[:field] @field_config = find_field_config_by_name_or_association(@field_name) unless @field_config render json: { error: "Field '#{@field_name}' not found" }, status: :not_found return end # Determine the correct parameter key (handle complex model names) param_key = determine_param_key_for_update_field # For belongs_to fields, we need to handle foreign key updates if @field_config[:type] == :belongs_to update_attrs = build_belongs_to_update_attributes(param_key) else update_attrs = build_regular_field_update_attributes(param_key) end if @record.update(update_attrs) handle_successful_field_update else handle_failed_field_update end end |