Skip to content

Commit bc3ff3b

Browse files
author
Nils Henning
committed
[REFACTOR] refactor last essential guides
1 parent 4a7bc94 commit bc3ff3b

File tree

5 files changed

+164
-101
lines changed

5 files changed

+164
-101
lines changed

docs/guides/2-essential/11_authentication_devise.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ class Admin::Pages::Persons::Index < Matestack::Ui::Page
267267
th text: 'Last name'
268268
th text: 'First name'
269269
th text: 'Role'
270+
th
270271
end
271272
end
272273

@@ -279,12 +280,17 @@ class Admin::Pages::Persons::Index < Matestack::Ui::Page
279280
end
280281
td text: person.first_name
281282
td text: person.role
283+
td class: 'text-right' do
284+
action delete_person_config(person) do
285+
button text: 'Delete', class: 'btn btn-outline-primary'
286+
end
287+
end
282288
end
283289
end
284290
end
285291

286292
def paginator
287-
ul class: 'pagination' do
293+
ul class: 'pagination justify-content-center' do
288294
li class: 'page-item' do
289295
collection_content_previous do
290296
button class: 'page-link', text: 'previous'
@@ -305,6 +311,20 @@ class Admin::Pages::Persons::Index < Matestack::Ui::Page
305311
end
306312
end
307313

314+
315+
def delete_person_config(person)
316+
{
317+
method: :delete,
318+
path: admin_person_path(person),
319+
success: {
320+
emit: 'persons-collection-update'
321+
},
322+
confirm: {
323+
text: "Do you really want to delete '#{person.first_name} #{person.last_name}'?"
324+
}
325+
}
326+
end
327+
308328
end
309329
```
310330

@@ -364,7 +384,7 @@ class Admin::Pages::Persons::New < Admin::Pages::Persons::Form
364384
div class: 'container' do
365385
div class: 'row' do
366386
div class: 'col-md-6 offset-md-3 text-center' do
367-
heading size: 2, text: 'Create new person'
387+
heading size: 2, text: 'Create new person', class: 'my-3'
368388
person_form 'Create'
369389
end
370390
end
@@ -399,7 +419,7 @@ class Admin::Pages::Persons::Edit < Admin::Pages::Persons::Form
399419
div class: 'container my-5' do
400420
div class: 'row' do
401421
div class: 'col-md-6 offset-md-3 text-center' do
402-
heading size: 2, text: "Edit Person: #{@person.first_name} #{@person.last_name}"
422+
heading size: 2, text: "Edit Person: #{@person.first_name} #{@person.last_name}", class: 'my-3'
403423
person_form 'Save changes'
404424
end
405425
end
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Essential Guide 12: Heroku Deployment with Postgres
2+
3+
## Introduction
4+
In this guide, we will
5+
- install and use PostgreSQL instead of SQLite3
6+
- deploy our application to heroku
7+
8+
## Prerequisites
9+
- Heroku CLI ([view installation details](https://devcenter.heroku.com/articles/getting-started-with-ruby#set-up))
10+
- Postgresql ([view installation details](https://devcenter.heroku.com/articles/heroku-postgresql#local-setup))
11+
12+
## Adding Postgres
13+
14+
In the Gemfile, replace the line starting with `gem 'sqlite3'` with `gem 'pg'`.
15+
16+
Make sure to run `bundle install` afterwards and replace the contents of `config/database.yml` with
17+
18+
<details>
19+
<summary>Note for Linux/Ubuntu users</summary>
20+
You may need to install additional libraries by running <br/>
21+
<code>sudo apt-get -y install postgresql postgresql-contrib libpq-dev</code>
22+
instead of only running <br/>
23+
<code>sudo apt-get install postgresql</code>.
24+
</details>
25+
<br/>
26+
27+
<details>
28+
<summary>Note for postgres role error</summary>
29+
If you get an error from postgres stating that your role is missing add it by creating a user. To do so run below codesnippet. <br/>
30+
<code>sudo su - postgres && createuser -s -r postgres</code>
31+
</details>
32+
<br/>
33+
34+
```yaml
35+
default: &default
36+
adapter: postgresql
37+
encoding: unicode
38+
# For details on connection pooling, see Rails configuration guide
39+
# https://guides.rubyonrails.org/configuring.html#database-pooling
40+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
41+
42+
development:
43+
<<: *default
44+
database: myapp_development
45+
46+
test:
47+
<<: *default
48+
database: myapp_test
49+
50+
production:
51+
<<: *default
52+
database: myapp_production
53+
username: myapp
54+
password: <%= ENV['MYAPP_DATABASE_PASSWORD'] %>
55+
```
56+
57+
## Deployment
58+
59+
To set up a new heroku project, run
60+
61+
```sh
62+
heroku create
63+
```
64+
65+
followed by
66+
67+
```sh
68+
git push heroku master
69+
```
70+
71+
to trigger a deployment.
72+
When we have new migrations or didn't initialize the database yet, we need to run
73+
74+
```sh
75+
heroku run rails db:migrate
76+
```
77+
78+
In an earlier guide we added some persons with seeds to our local database. In order to also seed some persons into our production database on heroku we need to run
79+
80+
```sh
81+
heroku run rake db:seed
82+
```
83+
84+
After the deployment, our database migrate and seeds task successfully finished we can visit our deployed application by running `heroku open`.
85+
86+
If you have used assets like we did in our application remember to run `heroku run rails assets:precompile`.
87+
88+
## Creating an admin
89+
90+
In order to be able to login, we need to create an admin. We could add one in our seeds but we wouldn't recommend doing it. Instead we can use another of herokus features. Opening a rails console connected with the production database of our live application.
91+
92+
```
93+
heroku run rails console
94+
```
95+
96+
After the console opened we can now create an admin using the `create` method of our `Admin` model with an email, password and password confirmation as parameters.
97+
98+
```ruby
99+
Admin.create(email: '[email protected]', password: 'OnlyForSuperMates', password_confirmation: 'OnlyForSuperMates')
100+
```
101+
102+
Now we can close the console and run `heroku open` again. We can now login to our admin app with the above specified credentials.
103+
104+
## Recap & outlook
105+
106+
We successfully deployed our application to heroku and learned what are the necessary steps to do this. We also switched our application database from sqlite to postgres, because heroku doesn't support sqlite.
107+
108+
While the application is good as it is right now, go ahead and check out the [last part of the essential guide](/docs/guides/2-essential/13_wrap_up.md).

docs/guides/2-essential/12_wrap_up.md

Lines changed: 0 additions & 32 deletions
This file was deleted.

docs/guides/2-essential/13_heroku_deployment.md

Lines changed: 0 additions & 66 deletions
This file was deleted.

docs/guides/2-essential/13_wrap_up.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Essential Guide 13: Wrap Up & Outlook
2+
3+
Welcome to the thirteenth part of our essential guide about building a web application with matestack.
4+
5+
## Quick recap
6+
7+
What have we got so far? After following the previous guides, there's now a `RubyOnRails` application running on `Heroku` with a public and admin area allowing for basic CRUD operations.
8+
9+
We have achieved this by setting up two matestack apps each with some matestack pages and by orchestrating matestacks components and vue.js components.
10+
11+
One of the matestack apps is only available after an admin has logged in and protected by the `Devise` gem. The application pleases the eye and offers a great user experience since we have set up and customized `Bootstrap`. Assets are being served by `Webpacker`.
12+
13+
What now?
14+
15+
## Be proud
16+
17+
Pat yourself on the shoulder - you've made it until here, and it was quite a journey! Make sure to push your code to a GitLab or GitHub repository so it will survive a possible change of gear.
18+
19+
## Customize your application
20+
21+
In this guide, we have followed a quite strict and pre-defined route. Now is the time for you to take over and change it according to your ideas!
22+
23+
## Further reading
24+
25+
Since you are now familiar with the basics behind the `matestack-ui-core` library, there is a good chance you want to digg deeper on specific topics. Check out our ever-evolving list of guides and read on as you want.
26+
27+
## Showcase
28+
29+
You're super proud of what you've built using `matestack` libraries? [Let us know](mailto:[email protected]) and become part of our showcase.
30+
31+
## Become part of the community
32+
33+
You're very invited to join our [chat]() or [Slack](), ask questions on our [forum]() or contribute by tackling [GitHub issues](https://github.com/matestack/matestack-ui-core/issues).

0 commit comments

Comments
 (0)