Reformat attribute before saving and return an error if needed

I'm making a web-app in RoR

I have a model with YouTube video ID so I can use it to embed videos to the web-page.

It works well but I want to make it easier for admins to add videos, and I've already found out how to parse the video's ID from YouTube's URL, but now I thing about where to add it.

I want to notify the user that he have entered the wrong data like the validation does, but if I add some parse_video_id model method or add a before_save hook, how can I add an error to the object so I can then tell about it to the user?

Answers


You add errors with:

errors.add(:attribute, message)

Need Your Help

Converting Timestamps

timestamp python-2.7

I am new to python. I need to convert the timestamp 2012-06-15T05:31:55Z in to seconds.

how can the vim script(clang_complete ) complete function ,template?

function vim autocomplete clang clang-complete

In the clang_complete.txt(the help file), it shows these in clang_complete-compl_kinds: