ruby on rails - Create input with maxlength based on database size -
how write text_field in view, automatically respects size of database field?
my migration:
t.string :name, limit: 100
my view:
<%= f.text_field :name %>
well, there way done. write code inside /helper
directory, , put method inside :
module applicationhelper def column_info model_name, field_name, option model_name.constantize.column_types[field_name].public_send option end end
now, use helper method anywhere inside view..
<%= f.text_field :name, size: column_info('person', :name, :limit) || 100 %>
Comments
Post a Comment