Skip to content

Commit edd238f

Browse files
committed
Readme %#$%
1 parent 444d060 commit edd238f

File tree

1 file changed

+37
-36
lines changed

1 file changed

+37
-36
lines changed

README.md

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ Now with [Rabl](https://github.com/nesquena/rabl) support!
1010
When you need to send some start data from your controller to your js
1111
you probably doing something like this:
1212

13-
1. Write this data in controller(presenter/model) in some variable
14-
2. In view for this action you put this data in some objects by data
15-
attributes, or write js right in view
16-
3. Then in js it depends - if you previously write data in data
17-
attributes - you should parse this attributes and write data to some
18-
js variable. If you write js right in view (many frontenders shame you for
19-
that) - you just use data from this js - OK.
20-
4. You can use your data in your js
13+
1. Write this data in controller(presenter/model) in some variable
14+
2. In view for this action you put this data in some objects by data
15+
attributes, or write js right in view
16+
3. Then in js it depends - if you previously write data in data
17+
attributes - you should parse this attributes and write data to some
18+
js variable. If you write js right in view (many frontenders shame you for
19+
that) - you just use data from this js - OK.
20+
4. You can use your data in your js
2121

2222
And everytime when you need some data from action to js you do this.
2323

2424
With gon you configure it firstly - just put in layout one tag, and add
2525
gem line to your Gemfile and do two actions:
2626

27-
1. Write variables by gon.variable_name = variable_value
28-
2. In your js you get this by gon.variable_name
29-
3. profit?
27+
1. Write variables by gon.variable_name = variable_value
28+
2. In your js you get this by gon.variable_name
29+
3. profit?
3030

3131
## Usage
3232

@@ -111,46 +111,47 @@ Now you can write your variables assign logic in templates with [Rabl](https://g
111111
How write templates very clearly described in their repo.
112112

113113
Profit of using Rabl with gon:
114-
1. You can clean your controllers now!
115-
2. Clear and easy work with database objects and collections
116-
3. All power of Rabl
117-
4. You still can be lazy and don't use common way to transfer data in js
118-
5. And so on
114+
115+
1. You can clean your controllers now!
116+
2. Clear and easy work with database objects and collections
117+
3. All power of Rabl
118+
4. You still can be lazy and don't use common way to transfer data in js
119+
5. And so on
119120

120121
For using gon with Rabl you need to create new Rabl template and map gon
121122
to it.
122123
For example you have model Post with attributes :title and :body.
123124
You want to get all your posts in your js as an Array.
124125
Thats what you need to do:
125126

126-
1. Create Rabl template. I preffer creating special directory for
127-
templates which are not view templates.
127+
1. Create Rabl template. I preffer creating special directory for
128+
templates which are not view templates.
128129

129-
`app/goners/posts/index.rabl`
130+
`app/goners/posts/index.rabl`
130131

131-
``` rabl
132-
collection @posts => 'posts'
133-
attributes :id, :title, :body
134-
```
132+
``` rabl
133+
collection @posts => 'posts'
134+
attributes :id, :title, :body
135+
```
135136

136-
2. After that you need only map this template to gon.
137+
2. After that you need only map this template to gon.
137138

138-
`app/controllers/post_controller.rb#index`
139+
`app/controllers/post_controller.rb#index`
139140

140-
``` ruby
141-
def index
142-
# some controller logic
143-
@posts = Post.all # Rabl works with instance variables of controller
141+
``` ruby
142+
def index
143+
# some controller logic
144+
@posts = Post.all # Rabl works with instance variables of controller
144145
145-
gon.rabl 'app/goners/posts/index.rabl'
146-
end
147-
```
146+
gon.rabl 'app/goners/posts/index.rabl'
147+
end
148+
```
148149

149-
Thats it! In your js now you get gon.posts variable which is Array of
150-
post objects with attributes :id, :title and :body.
150+
Thats it! In your js now you get gon.posts variable which is Array of
151+
post objects with attributes :id, :title and :body.
151152

152-
P.s. If you didn't put include_gon tag in your html head area - it
153-
wouldn't work. You can read about this in common usage above.
153+
P.s. If you didn't put include_gon tag in your html head area - it
154+
wouldn't work. You can read about this in common usage above.
154155

155156
### Some tips of usage Rabl with gon:
156157

0 commit comments

Comments
 (0)