开发者

Is there anything similar to ActiveModel for CoffeeScript or JavaScript?

I creating a new web site in Rails but I would like to give CoffeeScript/Node.JS a try, and the first thing I would like to do is validations, callbacks and associations on model classes in CoffeeScript (server-side). (maybe a more Domain-driven framework than Rails... =])

Is there something I could use?

Tks

update/more info: The thing is that I'm having problem building a model for a domain that it is more complex than the general domains (eg. blog/cms sample) in Rails. It seems that the DB-driven models in Rails and how it is coupled with DB functions isn't helping me on design my complex domain scenario (a more pure OO + mod开发者_StackOverflow社区el helpers like ActiveModel would help here).


There are quite a few choices. Various JavaScript frameworks will include something similar to ActiveModel, but that would be the model side only. They would also most likely come with something for views and controllers too, completing MVC.

Here's a small list of frameworks that I know of,

  • ActiveJS comes with its own ActiveRecord.Model which is heavily inspired by Rails.
  • Backbone.JS
  • Spine.JS - I supposed its meant to be a pun on backbone.
  • SproutCore


If you're looking for a way to validate models from a Node.js server the way you would with ActiveModel, you should look at this question: Validation library for Node.js

If you want client-side validation, there are many libraries (just Google "js validation library"); perhaps the most mature and feature-rich is jQuery Validation. It's form-oriented rather than model-oriented, but you should be able to map models and forms to each other fairly easily. Of course, in principle you can run any client-side JS library on Node.js, and Rails for that matter (see my RailsConf talk End-to-End CoffeeScript), using jsdom—a technique that I hope will take off in the future.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜