rails_script 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d9958511d98ea471627dc977879e6d035c35898
4
- data.tar.gz: 25902692ba8bb9c73879b978090a30cc26440668
3
+ metadata.gz: 6197061a840ea8852e564dfcc2d456362866834e
4
+ data.tar.gz: 304e6bda5fab18bf4f8579cc5507725f421caffe
5
5
  SHA512:
6
- metadata.gz: 3bae329972b4ade7e5f3ec70ec9a681b9b06f3c1d3a86c9d39bde356af002715e4a919f973a36c0f089aed29ed19ba1646cf3ec201b5078cec956f3186d483d9
7
- data.tar.gz: 26a1d353e5466280a883128165935bd41f7baa25b322625d548a71531d171f70309ceb0faf77533359b357feec44846adfc02b2db52f9716f6237f23e8706159
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
- clearEventHandlers: ->
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
@@ -1,3 +1,3 @@
1
1
  module RailsScript
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
@@ -6,17 +6,17 @@ class App.<%= class_name %> extends App.Base
6
6
  return this
7
7
 
8
8
 
9
- index: ->
9
+ index: =>
10
10
  return
11
11
 
12
12
 
13
- show: ->
13
+ show: =>
14
14
  return
15
15
 
16
16
 
17
- new: ->
17
+ new: =>
18
18
  return
19
19
 
20
20
 
21
- edit: ->
22
- return
21
+ edit: =>
22
+ return
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.0
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-08 00:00:00.000000000 Z
11
+ date: 2014-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler