Rails: serializing a model's validators into json -


After

I have been working with rail and frontend js frameworks and libs, amber, multiple including angular, and feedback. While all three libraries are powerful in their respective, a pain point (at least for me) has always been a form of legalization. I always hate to recognize the recognition of my model (in rail) with the verification of my form (Amber / Analer / React).

Recently, I was trying to sort the legalists of a model in JSN. However, by calling as_json on a record, I will return a Jason hash, it does not give me the type of validators for a special feature.

For example, suppose I have a model called assignment when I have a new assignment record and call _validators , I get it.

  pry (main)> Assignment.new_video1 = & gt; {: Title = & gt; [# & Lt; ActiveRecord :: Verification :: PresenceValidator: 0x0000010e123900 @ attributes = [: title], @options = {} & gt;] ,: full_prompt = & gt; [# & Lt; ActiveRecord :: Verification:: PresenceValidator: 0x0000010e122e60 @attributes = [: full_prompt], @options = {} & gt;] ,: submission_window = & gt; [# & Lt; ActiveRecord :: Verification :: PresenceValidator: 0x0000010e1223c0 @attributes = [: submission_window], @ option = {} & gt;]  

Now when I call as_json I get it when I add:

  pry (main)> Assignment.news.vi_vidators.as_jason = & gt; {"Title" = & gt; [{"Properties" = & gt; ["Title"], "options" = & gt; {}}], "Full_prompt" = & gt; [{"Properties" = & gt; ["Full_prompt"], "options" = & gt; {}}], "Submission_window" = & gt; [{"Properties" = & gt; ["Submission_window"], "options" = & gt; {}}]}  

You can see, calling as_json removes what type of are associated with the properties of a model Were.

Is there a similar situation and / or an alternative solution in one? Thanks for any help!

Kurt

This should work better ... attributes and options hash The sub-hash will be the value of a hash where the key is a valid square.

  hash = {} Assignment._validators.each {| K, v | V.each {| Well | Hash [k] || = {}; Hash [k] [val.class.to_s] = val}} hash.ass_jason  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -