Rails will refactor the class constants into the database corresponding to the table after the

Source: Internet
Author: User

Why do you have it? Don't worry, people with obsessive-compulsive disorder can't afford to hurt themselves! It's a little bit of a trifle. Feel itchy: is if the table payment_types often change what to do? Do you want to shut down the Rails Web server and restart it every time? That's too much trouble Bird, the final solution is that In order validation, it is mandatory to pull the payment type data from the table in the database each time, and the last modified ORDER.RB code is as follows:

Class Order < ActiveRecord::Base  has_many:line_items,dependent::d estroy  validates_each:p ay_type do | model,attr,val|    Unless PaymentType.types.include? (Val)      Model.errors.add (attr, ' Payment type not on the list ')    end  EndEnd

After a toss, stupid cat seems to understand a little: first to find out the real reason behind the problem is what, otherwise is nonsense; second, in the uncertainty when the pace is small, slow, do not expect a success, or the consequences are very painful, you know ...

Rails will refactor the class constants into the database corresponding to the table after the

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.