开发者

Can rails automatically find DB constraints and place this into your Model...?

As an Oracle ADF developer I am familiar with being able to create an Entity (the rails equivalent would be a Model) that includes all of the DB constraints (PK, FK, unique, length, any non-trigger induced constraint). As a result, in ADF I can very easily create a field on the view that is based on an Entities attribute.

For the sake of example, I place 3 such fields, one is a String (or VARCHAR2 in Oracle...) with a max length of 20, and the other is an INT and a DATE. The metadata (type, length constraints) are stored in the Model. And by default, any field generated with automatically include this validation on the front end. So, the first field, the String(20) will be a text input field with a max length of 20. So, question 1, will rails do this automatically on the front end or must I go and set this? Now, in ADF the int field that is placed on the view will not allow the user to enter non-digits (this will trigger on an attempt to update the Model (hitting submit, going to a new page). So, question 2, does rails automatically prevent non-digit开发者_如何学运维s? Also does rails have re-usable validation for simple things like phone numbers, addresses. Lastly, question 3, by default in ADF, any date will automatically generate a typical calendar widget for input. Does this also occur for rails? What does rails use for these kinds of javascript widgets if this isn't the case?


Rails does recognise your datamodel automatically, but does not add any validation and stuff automatically. Not sure why not, because all the knowledge is there. I guess it has something to do with performance?

I know of one plugin that does this for you though: dr. nic's magic-model-generator. It is not the same as ADF but it's a start. It investigates your datamodel and adds all the required validations and relations to your models.

As to dates, and forms, either you use something like formtastic, and then everything is somewhat automatic (adviseable). Or if you choose the more standard, manual way, use the calendar-date-select gem (gem install calendar_date_select).

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜