Disable Protected Attributes In ActiveRecordHelper Forms
Join the DZone community and get the full member experience.
Join For FreeTo make the form method in ActiveRecordHelper disable protected attribute, place the following in your application_help.rb:
def attr_protected?(record, column)
o = instance_variable_get("@#{record}")
o && o.class.protected_attributes &&
o.class.protected_attributes.include?(column.name.to_sym)
end
def default_input_block
Proc.new { |record, column|
options = attr_protected?(record, column) ? {:disabled => true} : {}
<<-"end_html"
#{input(record, column.name, options)}
end_html
}
end
And mark some attributes protected, for example:
class Item < ActiveRecord::Base
attr_protected :created_at
end
The created_at attribute will be rendered but won't be editable. This will work for "dynamic scaffolds" too!
Form (document)
Attribute (computing)
Opinions expressed by DZone contributors are their own.
Comments