Ajmal Afif's blog

Balancing between consuming knowledge and creating values.

Rails landing page with PostgresQL by Betakit

Tutorial

  1. Set up the server.
1
2
3
4
5
6
$ psql
psql (9.1.4)
Type "help" for help.

username=# CREATE DATABASE betakit_development;
CREATE DATABASE
  1. Migrate the database
1
$ rake db:migrate

That should output something like this:

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
$ rake db:migrate

==  CreateUsers: migrating ====================================================
-- create_table(:users)
NOTICE:  CREATE TABLE will create implicit sequence "users_id_seq" for serial column "users.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "users_pkey" for table "users"
   -> 0.0043s
==  CreateUsers: migrated (0.0043s) ===========================================

==  AddStateToUser: migrating =================================================
-- add_column(:users, :state, :integer, {:default=>0})
   -> 0.0048s
==  AddStateToUser: migrated (0.0049s) ========================================

==  AddStatsToUsers: migrating ================================================
-- add_column(:users, :stats, :text)
   -> 0.0014s
==  AddStatsToUsers: migrated (0.0015s) =======================================

==  AddRefererToUser: migrating ===============================================
-- add_column(:users, :referer_id, :integer)
   -> 0.0004s
==  AddRefererToUser: migrated (0.0004s) ======================================

==  AddUserAgentToUser: migrating =============================================
-- add_column(:users, :user_agent, :string)
   -> 0.0004s
==  AddUserAgentToUser: migrated (0.0004s) ====================================

==  CreateStatistics: migrating ===============================================
-- create_table(:statistics)
NOTICE:  CREATE TABLE will create implicit sequence "statistics_id_seq" for serial column "statistics.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "statistics_pkey" for table "statistics"
   -> 0.0033s
==  CreateStatistics: migrated (0.0034s) ======================================

==  AddCohorts: migrating =====================================================
-- remove_column(:statistics, :cohort)
   -> 0.0006s
-- add_column(:statistics, :cohort_name, :text)
   -> 0.0016s
-- add_column(:statistics, :cohort_value, :text)
   -> 0.0005s
-- add_column(:statistics, :sample_size, :integer)
   -> 0.0003s
==  AddCohorts: migrated (0.0033s) ============================================

==  RenameCohort: migrating ===================================================
-- rename_column(:statistics, :cohort_value, :cohort_group)
   -> 0.0005s
==  RenameCohort: migrated (0.0006s) ==========================================

Some issues I had

No database found

Fixed by creating database for it in Terminal:

1
2
3
4
5
6
$ psql
psql (9.1.4)
Type "help" for help.

username=# CREATE DATABASE betakit_development;
CREATE DATABASE

Login details not found for localhost

So by default the root URL should link you to the admin page. Let’s have a look at that with rake routes:

1
2
3
4
5
6
7
8
9
10
$ rake routes
                    /                             admin#home
         dashboard  /dashboard(.:format)          admin#reports
                    /report/:stat_name(.:format)  admin#report_stat
api_request_invite  /api/request_invite(.:format) api#request_invite
   api_invite_user  /api/invite_user(.:format)    admin#invite_user
 api_import_emails  /api/import_emails(.:format)  admin#import_emails
 api_export_emails  /api/export_emails(.:format)  admin#export_emails
api_increment_stat  /api/increment_stat(.:format) api#increment_stat
  api_set_app_stat  /api/set_app_stat(.:format)   api#set_app_stat

Now when you visit your root URL of your local copy of betakit (let’s called it http://betakit.dev/ for the sake of example), you will have a prompt that asked for admin and password. How do you log in and get pass that?

Have a look at config/environments/development.rb and you will see this:

1
2
3
# Auth Settings for development
config.auth_username = "admin"
config.auth_password = "password"

So go ahead and fill those in and voila!

Routing root (/) to client/clientTestPage.html

For now

Resource: http://stackoverflow.com/questions/5631145/routing-to-static-html-page-in-public

Inside config/routes.rb

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Betakit::Application.routes.draw do

  match '/', :to => redirect('/client/clientTestPage.html')

  match '/admin' => 'admin#home'
  match '/dashboard' => 'admin#reports'
  match '/report/:stat_name' => 'admin#report_stat'

  match '/api/request_invite' => 'api#request_invite'
  match '/api/invite_user' => 'admin#invite_user'
  match '/api/import_emails' => 'admin#import_emails'
  match '/api/export_emails' => 'admin#export_emails'
  match '/api/increment_stat' => 'api#increment_stat'
  match '/api/set_app_stat' => 'api#set_app_stat'

end

Setup for SendGrid

  • Still in progress. Have to wait if it works while account is being provisioned.

Comments