-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhowto-notes.txt
149 lines (99 loc) · 8.09 KB
/
howto-notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
rails s
^to start the project. Visit localhost:3000 to see the app
~~~
After creating a new Rails app,
Go to config/routes.rb and start adding “routes” which respond to URLs that you visit, and they look like this:
root to: "home#index"
Where root refers to the “index page” of the site, and home is the name of a controller and index is the name of a method in that controller.
root is a method that takes a hash of “to” and some value. Ruby often uses hashes of known keys and unknown values to supply information to its methods.
Then, make sure there is a corresponding controller!
Example:
Create controllers/home_controller.rb
This should contain the method that was referenced in routes.rb; for example, index
Adding another route to routes.rb, ABOVE the root one:
get "search", to: "home#index"
This uses the URL /search and uses the same index method in the home_controller.rb controller
If there’s no matching method for a controller, it will go to /app/views/<controller_name> where controller_name is the short name of the controller, and render an index file from there, e.g. index.html.erb.
Useful website for testing javascript on the fly:
https://jsfiddle.net/#run
Add our index.html.erb and our home.js
Note: the javascript was loading before the form, so we had to wrap it in
$(document).ready(function() {
});
Use this URL to test search terms:
http://localhost:3000/api/community?term=foo
Right now this is using the code from app/controllers/api/communities_controller.rb
And it shows a JSON output of the term
~~~~~~
On to the community search!
Use Nokogiri to scrape the community page and have app/controllers/api/communities_controller.rb show the results from that page.
After installing Nokogiri, adding it to my Gemfile, and running bundle install,
I was able to add the following lines to app/controllers/api/communities_controller.rb:
require 'open-uri'
@doc = Nokogiri::HTML(open("https://www.digitalocean.com/community/search?q=coreos"))
articles = @doc.css("div.feedable-details a")
puts articles
This uses a request to a static page, https://www.digitalocean.com/community/search?q=coreos.
TODO: Sub in that “term” variable!
It grabs the page as a Nokogiri object, and then I searched through it for items related to the CSS descriptor feedable-details.
I don’t remember how to show things on the page yet so I’m just using “puts” to send the output to the terminal.
So far it looks like I got what I wanted in the terminal!
TODO: Clean up the requested output a little more, and figure out how to properly display it on the app web page. (Probably need a view for this?)
TODO: Parse multiple web pages from the community site
Started GET "/api/community?term=coreos" for ::1 at 2016-10-30 15:17:48 -0400
Processing by Api::CommunitiesController#show as HTML
Parameters: {"term"=>"coreos"}
<a href="/community/tutorials/an-introduction-to-coreos-system-components">An Introduction to <em>CoreOS</em> System Components</a>
<a class="series" data-toggle="tooltip" href="/community/tutorial_series/getting-started-with-coreos-2" title="Getting Started with CoreOS">Series 1/9</a>
<a href="/community/tutorials/how-to-set-up-a-coreos-cluster-on-digitalocean">How To Set Up a <em>CoreOS</em> Cluster on DigitalOcean</a>
<a class="series" data-toggle="tooltip" href="/community/tutorial_series/getting-started-with-coreos-2" title="Getting Started with CoreOS">Series 2/9</a>
<a href="/community/tutorials/how-to-create-and-run-a-service-on-a-coreos-cluster">How To Create and Run a Service on a <em>CoreOS</em> Cluster</a>
<a class="series" data-toggle="tooltip" href="/community/tutorial_series/getting-started-with-coreos-2" title="Getting Started with CoreOS">Series 5/9</a>
<a href="/community/tutorials/how-to-install-and-configure-kubernetes-on-top-of-a-coreos-cluster">How To Install and Configure Kubernetes on top of a <em>CoreOS</em> Cluster</a>
<a href="/community/tutorials/how-to-perform-continuous-integration-testing-with-drone-io-on-coreos-and-docker">How To Perform Continuous Integration Testing with Drone.io on <em>CoreOS</em> and Docker</a>
<a href="/community/tutorials/how-to-use-fleet-and-fleetctl-to-manage-your-coreos-cluster">How To Use Fleet and Fleetctl to Manage your <em>CoreOS</em> Cluster</a>
<a class="series" data-toggle="tooltip" href="/community/tutorial_series/getting-started-with-coreos-2" title="Getting Started with CoreOS">Series 3/9</a>
<a href="/community/tutorials/how-to-use-confd-and-etcd-to-dynamically-reconfigure-services-in-coreos">How To Use Confd and Etcd to Dynamically Reconfigure Services in <em>CoreOS</em></a>
<a class="series" data-toggle="tooltip" href="/community/tutorial_series/getting-started-with-coreos-2" title="Getting Started with CoreOS">Series 7/9</a>
<a href="/community/tutorials/how-to-use-etcdctl-and-etcd-coreos-s-distributed-key-value-store">How To Use Etcdctl and Etcd, <em>CoreOS</em>'s Distributed Key-Value Store</a>
<a class="series" data-toggle="tooltip" href="/community/tutorial_series/getting-started-with-coreos-2" title="Getting Started with CoreOS">Series 4/9</a>
<a href="/community/tutorials/how-to-create-flexible-services-for-a-coreos-cluster-with-fleet-unit-files">How to Create Flexible Services for a <em>CoreOS</em> Cluster with Fleet Unit Files</a>
<a class="series" data-toggle="tooltip" href="/community/tutorial_series/getting-started-with-coreos-2" title="Getting Started with CoreOS">Series 6/9</a>
<a href="/community/tutorials/how-to-secure-your-coreos-cluster-with-tls-ssl-and-firewall-rules">How To Secure Your <em>CoreOS</em> Cluster with TLS/SSL and Firewall Rules</a>
<a class="series" data-toggle="tooltip" href="/community/tutorial_series/getting-started-with-coreos-2" title="Getting Started with CoreOS">Series 9/9</a>
<a href="/community/tutorials/how-to-use-the-ambassador-pattern-to-dynamically-configure-services-on-coreos">How To Use the Ambassador Pattern to Dynamically Configure Services on <em>CoreOS</em></a>
<a href="/community/tutorials/how-to-troubleshoot-common-issues-with-your-coreos-servers">How To Troubleshoot Common Issues with your <em>CoreOS</em> Servers</a>
<a class="series" data-toggle="tooltip" href="/community/tutorial_series/getting-started-with-coreos-2" title="Getting Started with CoreOS">Series 8/9</a>
<a href="/community/tutorials/how-to-securely-set-up-shipyard-2-0-10-with-tls-on-coreos">How To Securely Set Up Shipyard 2.0.10 with TLS on <em>CoreOS</em></a>
<a href="/community/questions/resizing-digital-ocean-droplets-that-use-coreos-break-the-coreos-cluster">Resizing Digital Ocean Droplets that use <em>CoreOS</em> break the <em>CoreOs</em> Cluster.</a>
<a href="/community/users/milo388195">
milo388195
</a>
<a href="/community/questions/how-can-i-use-block-storage-with-a-coreos-cluster">How can I use block storage with a <em>coreos</em> cluster?</a>
<a href="/community/users/leesylvester">
leesylvester
</a>
<a href="/community/questions/docker-tcp-socket-fails-on-coreos">docker-tcp.socket fails on <em>coreos</em></a>
<a href="/community/users/pancake">
PanCake
</a>
<a href="/community/questions/coreos-setup-error-503-fleet-server-unable-to-communicate-with-etcd"><em>CoreOS</em> Setup: Error 503: fleet server unable to communicate with etcd</a>
<a href="/community/users/computer-geek-c">
computer.geek.c
</a>
<a href="/community/questions/coreos-fleet-clustering-high-availability-problem"><em>CoreOS</em> Fleet Clustering High Availability Problem</a>
<a href="/community/users/jhahm">
JHahm
</a>
<a href="/community/questions/simplest-way-to-use-coreos-with-wordpress">Simplest way to use <em>CoreOS</em> with Wordpress?</a>
<a href="/community/users/eli160638">
eli160638
</a>
<a href="/community/questions/why-some-time-my-coreos-hangs">Why some time my <em>coreos</em> hangs?</a>
<a href="/community/users/nonlux">
nonlux
</a>
<a href="/community/questions/recovery-of-a-coreos-image">Recovery of a <em>CoreOS</em> image</a>
<a href="/community/users/texascacto">
texascacto
</a>