rails_script 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6197061a840ea8852e564dfcc2d456362866834e
|
4
|
+
data.tar.gz: 304e6bda5fab18bf4f8579cc5507725f421caffe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9259d6e1a66ca0f80574c0f880910eec9a08949613aa8c127afe46ffa80a1c622faa5060e0830c6ade711c7d460e02400a939e0f487668706239b0649494ada5
|
7
|
+
data.tar.gz: 8d2468b993f087e0885468b0bd3fae3c1d3c3db10a40aee0fab918fdea634c5b5b742fe26fe6ec6259f2bba5ee8afb0c66fd86511f06ab73cd540132cf0e1d80
|
data/README.md
CHANGED
@@ -284,6 +284,36 @@ class App.MyClassName
|
|
284
284
|
|
285
285
|
To pass data from Rails to JavaScript, just define ```@to_javascript```. This is then converted to a JSON object with ```@to_javascript.to_json``` and can be accessed with ```Utility.RailsVars```.
|
286
286
|
|
287
|
+
Here's an example where ```@to_javascript``` is used in a ```before_filter``` to pass the current user and their friends:
|
288
|
+
```
|
289
|
+
# /app/controllers/application_controller.rb
|
290
|
+
|
291
|
+
class ApplicationController
|
292
|
+
|
293
|
+
before_filter :set_javascript_vars
|
294
|
+
|
295
|
+
private
|
296
|
+
|
297
|
+
def set_javascript_vars
|
298
|
+
@to_javascript = { user: current_user, friends: current_user.friends }
|
299
|
+
end
|
300
|
+
|
301
|
+
end
|
302
|
+
```
|
303
|
+
|
304
|
+
And here's how we print that data to the console on the ```users#index``` action:
|
305
|
+
|
306
|
+
```
|
307
|
+
# /app/assets/javascripts/users.js.coffee
|
308
|
+
|
309
|
+
window.App ||= {}
|
310
|
+
class App.Users extends App.Base
|
311
|
+
|
312
|
+
index: =>
|
313
|
+
console.log App.Utility.RailsVars.user
|
314
|
+
console.log App.Utility.RailsVars.friends
|
315
|
+
```
|
316
|
+
|
287
317
|
|
288
318
|
### Events
|
289
319
|
|
@@ -29,9 +29,9 @@ class App.Base
|
|
29
29
|
when each new page is fetched. Adding a namespace to your events will prevent them from being removed between page
|
30
30
|
loads, i.e. "$(window).on 'scroll.app', myHandler"
|
31
31
|
###
|
32
|
-
|
32
|
+
setClearEventHandlers: ->
|
33
33
|
jQuery(document).on 'page:before-change', ->
|
34
34
|
for element in [window, document]
|
35
35
|
for event, handlers in jQuery._data(element, 'events')
|
36
36
|
for handler in handlers
|
37
|
-
if handler.namespace == '' then $(element).off event, handler.handler
|
37
|
+
if handler.namespace == '' then $(element).off event, handler.handler
|
data/lib/rails_script/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_script
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Pheasey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|