You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/tutorial/todo.md
+21-70Lines changed: 21 additions & 70 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,13 @@
1
1
2
-
# TodoMVC Tutorial (Rails 5.2.0)
2
+
# TodoMVC Tutorial (Rails 5.2.x)
3
3
4
4
### Prerequisites
5
5
6
6
{ [Ruby On Rails](http://rubyonrails.org/) }
7
7
8
8
### The Goals of this Tutorial
9
9
10
-
In this tutorial you will build the classic [TodoMVC](http://todomvc.com) application using Hyperloop
10
+
In this tutorial, you will build the classic [TodoMVC](http://todomvc.com) application using Hyperloop. This tutorial will demonstrate all Hyperloop concepts - client side Components and Isomorphic Models.
11
11
12
12
The finished application will
13
13
@@ -20,74 +20,23 @@ The finished application will
20
20
21
21
You will write less than 100 lines of code, and the tutorial should take about 1-2 hours to complete.
22
22
23
-
You can find the older application source code here:
24
-
25
-
26
23
### Skills required
27
24
28
-
Working knowledge of Rails and Hyperloop required
25
+
Working knowledge of Rails required
29
26
30
27
### Chapter 1: Setting Things Up
31
28
32
-
Create a new rails application
33
-
```ruby
34
-
rails _5.2.0_ new hyperloop_todo
35
-
```
36
-
_5.2.0_ will insure you are creating a rails 5.2 appear (tested with 5.0 and 5.1)
37
-
38
-
Add Hyperloop to your Gemfile
39
-
40
-
Until our official release, add the following to your Gemfile:
Once the Hyperloop Gem and all its dependencies have been installed, it's time to run the hyperloop install generator.
55
-
```ruby
56
-
rails g hyperloop:install
57
-
```
58
-
59
-
The generator creates the hyperloop structure inside the /app directory :
60
-
```ruby
61
-
/app/hyperloop/
62
-
/app/hyperloop/components
63
-
/app/hyperloop/models
64
-
/app/hyperloop/operations
65
-
/app/hyperloop/stores
66
-
```
67
-
68
-
And updates your app/assets/javascripts/application.js file adding these lines:
69
-
```ruby
70
-
//=require hyperloop-loader
71
-
Opal.OpalHotReloader.$listen() // optional (port, false, poll_seconds) i.e. (8081, false, 1)
72
-
```
29
+
+`rails new MyApp`
30
+
+`cd MyApp` directory
31
+
+ add `gem 'hyperloop'` to the Gemfile
32
+
+`bundle install`
33
+
+`run rails g hyperloop:install`
73
34
74
-
To be sure everything is setting up correctly, check your app/assets/javascripts/application.js:
75
-
```ruby
76
-
...
77
-
//=require rails-ujs
78
-
//=require activestorage
79
-
//=require turbolinks
80
-
//= require_tree .
81
-
//=require hyperloop-loader
82
-
Opal.OpalHotReloader.$listen() // optional (port, false, poll_seconds) i.e. (8081, false, 1)
83
-
```
35
+
#### Start the Rails app
84
36
85
-
Run foreman
86
-
```ruby
87
-
$ foreman start
88
-
```
37
+
+`bundle exec foreman start` to start Rails and OpalHotReloader
89
38
90
-
Navigate to the given location and you should see the word **App** displayed on the page.
39
+
Navigate to `http://localhost:5000/` and you should see the word **App** displayed on the page.
91
40
92
41
### Chapter 2: Hyperloop Models are Rails Models
93
42
@@ -97,11 +46,11 @@ We are going to add our Todo Model, and discover that Hyperloop models are in fa
97
46
+ Changes to models on the server are synchronized with all participating browsers.
98
47
+ Data access is is protected by a robust *policy* mechanism.
99
48
100
-
>*A Rails ActiveRecord Model is a Ruby class that is backed by a database table. In this example we will have one model class called `Todo`. When manipulating models, Rails automatically generates the necessary SQL code for you. So when `Todo.all` is evaluated Rails generates the appropriate SQL
101
-
and turns the result of the query into appropriate Ruby data structures.*
49
+
>A Rails ActiveRecord Model is a Ruby class that is backed by a database table. In this example we will have one model class called `Todo`. When manipulating models, Rails automatically generates the necessary SQL code for you. So when `Todo.all` is evaluated Rails generates the appropriate SQL
50
+
and turns the result of the query into appropriate Ruby data structures.
102
51
103
-
>*Hyperloop Models are extensions of ActiveRecord Models that synchronize the data between the client and server
104
-
automatically for you. So now `Todo.all` can be evaluated on the server or the client.*
52
+
**Hyperloop Models are extensions of ActiveRecord Models that synchronize the data between the client and server
53
+
automatically for you. So now `Todo.all` can be evaluated on the server or the client.**
105
54
106
55
Okay lets see it in action:
107
56
@@ -130,11 +79,13 @@ Okay lets see it in action:
130
79
which will create the table.
131
80
132
81
2.**Make Some Models Public:**
133
-
*Move*`models/todo.rb` and `models/application_record.rb` to `hyperloop/models`.
134
82
135
-
This will make the model accessible on the clients *and the server*, subject to any data access policies.
83
+
+*Move*`models/todo.rb` to `hyperloop/models`
84
+
+ Stop and restart your rails server
85
+
86
+
This will make the model accessible on the clients *and the server*, subject to any data access policies.
136
87
137
-
*Note: The hyperloop installer adds a policy that gives full permission to all clients but only in development and test modes. Have a look at `app/policies/application_policy` if you are interested.*
88
+
*Note: The hyperloop installer adds a policy that gives full permission to all clients but only in development and test modes. Have a look at `app/policies/application_policy` if you are interested.*
138
89
139
90
3.**Try It**
140
91
Change your `App` component's render method to:
@@ -966,4 +917,4 @@ end
966
917
967
918
3: Its possible to get things so messed up the hot-reloader will not work. Restart the server and reload the browser.
968
919
969
-
You can find the final application source code here:
920
+
4: Reach out to us on Gitter, we are always happy to help get you onboarded!
0 commit comments