Project

omgjs

0.0
No commit activity in last 3 years
No release in over 3 years
A rails plugin which will automatically build your ActiveResource Models into Javascript models
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 0
>= 3.0.0
 Project Readme

The Opal Model Generator (OMG)¶ ↑

The goal of this project is to unobtrusively make javascript objects for each desired ActiveModel implementation in a rails project. These javascript objects will allow you to run the expecting fetching, deleting, and saving methods expected as if you were in a rails environment. This project isn’t disimilar to Vienna (github.com/opal/vienna), but is trying out going a step further by not requiring the user to rewrite the objects.

Long way to go with this project, but presently if you include the omgjs gem

gem 'omgjs', :git => 'https://github.com/trevorgrayson/omgjs.git'

and reference the required javascript files in your layout:

Presuming you are using rails assets, you’re going to want to add the following lines to your application.js file.

//= require opal
//= require active_record
//= require omg

otherwise you’ll do the traditional linking in your public folder:

<script type="text/javascript" src="/javascripts/opal.js"></script>
<script type="text/javascript" src="/javascripts/active_record.js"></script>
<script type="text/javascript" src="/javascripts/omg.js"></script>

The first is Opal’s required library. The second, active_record, is the equivilent of ActiveRecord::Base in rails, and will do all the heavy lifting for these objects. Lastly, omg, will have a list of all your ActiveModels in the app/models/ directory. You will rebuild this file in development everytime you refresh your browser.

You should be able to immediately load a page and find your models under the “Opal” namespace:

<script>
  Opal.YourModelName.find(1)

  Opal.YourModelName.find('all', {conditions: 'id > 2'})

</script>