-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
30 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,13 +1,40 @@ | |||
Jsvars | Jsvars | ||
====== | ====== | ||
Requires Json (require 'json') | |||
|
|
||
Introduction goes here. | This rails plugin will hide the messiness of passing variables from rails into javascript. It will automatically add the js needed to create a variable you define in rails, or add variables to objects. | ||
|
|
||
|
|
||
Example | Example | ||
======= | ======= | ||
|
|
||
Example goes here. | in your controller: | ||
|
|
||
jsvars[:loginPath] = login_path | |||
- Will create a global variable in the JS window object named 'loginPath' with the value you assigned. | |||
|
|
||
Copyright (c) 2009 [name of plugin creator], released under the MIT license | jsvars[:myObject] = {:title => "My Page", :email => "me@example.com"} | ||
- Adds the object variables that can be used as myObject.title & myObject.email in the view javascipt. | |||
- This will add the object "myObject" if it does not exist, if it already does, only the variables will be added to the already existing object. | |||
|
|||
Example of extending an object: | |||
In controller: | |||
jsvars[:login] = {:path => '/login'} | |||
|
|||
in view: | |||
<script> | |||
var login = { | |||
loginFuntion: function () { | |||
// .... | |||
}, | |||
specialVar: "My special Var" | |||
}; | |||
</script> | |||
|
|||
in JS: | |||
login.loginFunction = function() | |||
login.specialVar = 'My special Var' | |||
login.path = '/login' | |||
|
|||
|
|||
Copyright (c) 2009 Erick Schmitt, released under the MIT license |