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

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -