Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow removal of attributes #416

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/trestle/adapters/active_record_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ def human_attribute_name(attribute, options={})

def default_table_attributes
default_attributes.reject do |attribute|
inheritance_column?(attribute) || counter_cache_column?(attribute)
inheritance_column?(attribute) || counter_cache_column?(attribute) || admin.remove_table_attributes&.include?(attribute.name.to_s)
end
end

def default_form_attributes
default_attributes.reject do |attribute|
primary_key?(attribute) || inheritance_column?(attribute) || counter_cache_column?(attribute)
primary_key?(attribute) || inheritance_column?(attribute) || counter_cache_column?(attribute) || admin.remove_form_attributes&.include?(attribute.name.to_s)
end
end

Expand Down
3 changes: 3 additions & 0 deletions lib/trestle/admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class << self
attr_accessor :menu

attr_accessor :form
attr_accessor :remove_form_attributes
attr_accessor :remove_table_attributes
attr_accessor :remove_select_attributes

attr_writer :options
attr_writer :breadcrumb
Expand Down
6 changes: 5 additions & 1 deletion lib/trestle/form/automatic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ def initialize(admin, options={})
else
prompt = I18n.t("admin.form.select.prompt", default: "- Select %{attribute_name} -", attribute_name: admin.human_attribute_name(attribute.association_name))

select attribute.name, attribute.association_class.all, include_blank: prompt
if admin.remove_select_attributes.include?(attribute.name.to_s)
text_field attribute.name
else
select attribute.name, attribute.association_class.all, include_blank: prompt
end
end
when :text
text_area attribute.name
Expand Down