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

Fixed bug when attribute is named 'to'. Fixed checking editable? #1622

Merged
Merged
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
2 changes: 1 addition & 1 deletion lib/rails_admin/adapters/active_record/abstract_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def initialize(object)
end

def set_attributes(attributes, role = nil)
object.assign_attributes(attributes, :as => role)
object.assign_attributes(attributes)
end

def save(options = { :validate => true })
Expand Down
8 changes: 1 addition & 7 deletions lib/rails_admin/config/fields/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,7 @@ def virtual?
end

def editable?
return false if @properties && @properties[:read_only]
active_model_attr_accessible = !bindings[:object].class.active_authorizer[bindings[:view].controller.send(:_attr_accessible_role)].deny?(self.method_name)
return true if active_model_attr_accessible
if RailsAdmin::Config.yell_for_non_accessible_fields
Rails.logger.debug "\n\n[RailsAdmin] Please add 'attr_accessible :#{self.method_name}' in your '#{bindings[:object].class}' model definition if you want to make it editable.\nYou can also explicitely mark this field as read-only: \n\nconfig.model #{bindings[:object].class} do\n field :#{self.name} do\n read_only true\n end\nend\n\nAdd 'config.yell_for_non_accessible_fields = false' in your 'rails_admin.rb' initializer if you do not want to see these warnings\n\n"
end
false
!(@properties && @properties[:read_only])
end

# Is this an association
Expand Down
9 changes: 8 additions & 1 deletion lib/rails_admin/config/fields/factories/enum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
require 'rails_admin/config/fields/types/enum'

RailsAdmin::Config::Fields.register_factory do |parent, properties, fields|
if parent.abstract_model.model.respond_to?("#{properties[:name]}_enum") || parent.abstract_model.model.method_defined?("#{properties[:name]}_enum")

_model = parent.abstract_model.model
_method_name = "#{properties[:name]}_enum"

#NOTICE: _method_name could be `to_enum` and this method defined in Object.
if !Object.respond_to?(_method_name) && \
(_model.respond_to?(_method_name) || \
_model.method_defined?(_method_name))
fields << RailsAdmin::Config::Fields::Types::Enum.new(parent, properties[:name], properties)
true
else
Expand Down