ruby on rails - How to temporarily change the default value of column? -


I have a model that has several predefined rows (> 100) and can be edited by the user as well. I want to distinguish between pre-defined and user-added rows.

Because the database will be edited by a third-party application, I also want to be in the safe side and set the default value in the database schema predefined to False , because setting it to true will take serious restrictions on the line (i.e. it can never be removed)

On the other hand, the installed script creates 100 predefined rows; For each line Predefined = true must specify who is going to hide the script.

This is not bad, but if there is an easy way to change the train by default, then it makes my script more friendly.

In other words: I want to write it:

MyModel.create (: data => "value") < P> But what do I do:

  MyModel.create (: data = & gt; "value", predefined = true)  

is it possible?

Edit: This is just an examply, actually there are some more columns I have to set aside for the predefined column.

You can do this in two different ways:

Your migration In:

  t column: boolean: string,: default => True  

This defines the default value directly in the database when you change it, you have to create a new migration.

In your model:

  def before_create predefined = true if predefined. Nil? End  

defines this value as "true" unless you define it in advance. You can change the value by turning it into a model.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -