mysql - Best way to simulate default value for TEXT column using Ruby on Rails? -
i'm using text column in mysql database. documentation says, not possible set default value these columns.
i'm using following code simulate behavior:
class data before_save lambda {text_column ||= ''} end
is there better, more railis/active_record way this?
if you're happy html5 solution, have tried :placeholder attribute on :text_field?
also want stuff text_field (which captures small amount of text) "text" type column? did mean text_area?
if want "default value" stored in database if user doesnt input suggest following. it's "factory" pattern.
instead of calling "new" on activerecord model class, create "setup" method in model
def self.setup(params = {}) new(params).tap |v| v.text_column = "default value" # other defaultings end end
in controller instead of calling new on class call setup.
Comments
Post a Comment