Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 192 lines (132 sloc) 6.988 kb
9e942d3 Added README
Martin Kleppmann authored
1 Software-as-a-Service (SaaS) Rails template
2 ===========================================
f1de9cd Step-by-step instructions for using this template
Martin Kleppmann authored
3
4 Using this template in your application:
5
6 $ rails --database mysql myapp
7 $ cd myapp
8 $ rm -r README test # we use RSpec rather than Test::Unit
9 $ git init
10 $ git add .
11 $ git commit -m 'Auto-generated Rails project'
12 $ git remote add saas git@github.com:ept/saas-template.git
13 $ git pull saas master
14
ce65335 Remember requested URL in return_to URL parameter
Martin Kleppmann authored
15 Resolve any merge conflicts, then do `git commit -a`. When that is done, make sure git
16 has downloaded all required submodules:
f1de9cd Step-by-step instructions for using this template
Martin Kleppmann authored
17
ce65335 Remember requested URL in return_to URL parameter
Martin Kleppmann authored
18 $ git submodule init
19 $ git submodule update
20
21 Create databases `myapp_development` and `myapp_test` (or whatever you called the app),
22 tweak database config if necessary.
23
24 Add the following to `config/environment.rb` just after the `require File.join(File.dirname(__FILE__), 'boot')` line:
25
26 # Include our custom configuration parameters (see lib/environment_config.rb)
27 require 'environment_config'
28
29 and in the same file inside the `Rails::Initializer.run` block:
3bfba73 site_keys for password encryption
Martin Kleppmann authored
30
31 config.gem "rubyist-aasm", :lib => 'aasm', :source => "http://gems.github.com"
9c7bcbe Minimal admin interface scaffolding
Martin Kleppmann authored
32 config.gem "fastercsv"
f67ebd9 Global domain name config and user mailer
Martin Kleppmann authored
33 config.active_record.observers = :mailing_observer
ce65335 Remember requested URL in return_to URL parameter
Martin Kleppmann authored
34
9c7bcbe Minimal admin interface scaffolding
Martin Kleppmann authored
35 Add the following to `config/initializers/mime_types.rb`:
36
37 Mime::Type.register "text/csv", :csv
38
f67ebd9 Global domain name config and user mailer
Martin Kleppmann authored
39 Add the following to `config/environments/development.rb`:
ce65335 Remember requested URL in return_to URL parameter
Martin Kleppmann authored
40
f67ebd9 Global domain name config and user mailer
Martin Kleppmann authored
41 # Do not redirect to HTTPS URLs during development
42 config.https_login = false
43
44 # Set the base domain name under which our site is hosted
45 config.domain_name = 'example.local'
46
47 Add the following to `config/environments/test.rb`:
48
49 # Do not redirect to HTTPS URLs while testing
ce65335 Remember requested URL in return_to URL parameter
Martin Kleppmann authored
50 config.https_login = false
3bfba73 site_keys for password encryption
Martin Kleppmann authored
51
f67ebd9 Global domain name config and user mailer
Martin Kleppmann authored
52 # Set the base domain name under which our site is hosted
53 config.domain_name = 'test.host'
54
55 Add the following to `config/environments/production.rb`:
56
cb11ae4 Add exception_notification
Martin Kleppmann authored
57 # People to pester if an unhandled exception occurs
58 ExceptionNotifier.exception_recipients = %w(admin@example.com)
59
f67ebd9 Global domain name config and user mailer
Martin Kleppmann authored
60 # Set this to true if you want the login form to redirect to a https:// URL
61 config.https_login = false
4f27e1b Environment settings
Martin Kleppmann authored
62
f67ebd9 Global domain name config and user mailer
Martin Kleppmann authored
63 # Set the base domain name under which our site is hosted
64 config.domain_name = 'example.com' # Set to your real domain name!
4f27e1b Environment settings
Martin Kleppmann authored
65
3bfba73 site_keys for password encryption
Martin Kleppmann authored
66 Edit `config/initializers/site_keys.rb` and change the value for `REST_AUTH_SITE_KEY`
67 to something unique and random.
68
986a499 Regenerate fixtures with site key; add routes
Martin Kleppmann authored
69 Run `script/console` and run the following code to ensure the fixtures are regenerated
70 for your new site key:
71
72 def secure_digest(*args)
73 Digest::SHA1.hexdigest(args.flatten.join('--'))
74 end
75
76 def make_token
77 secure_digest(Time.now, (1..10).map{ rand.to_s })
78 end
79
80 def password_digest(password, salt)
81 digest = REST_AUTH_SITE_KEY
82 REST_AUTH_DIGEST_STRETCHES.times do
83 digest = secure_digest(digest, salt, password, REST_AUTH_SITE_KEY)
84 end
85 digest
86 end
87
88 def options
89 {:include_activation => true, :stateful => true}
90 end
91
92 f=File.new('vendor/plugins/restful_authentication/generators/authenticated/templates/spec/fixtures/users.yml', 'r')
93 contents=f.read
94 rendered = ERB.new(contents, nil, '-').result.gsub(/login/, 'name')
95 File.open('spec/fixtures/users.yml', 'w'){|f| f.write(rendered)}
96
97
3a28a6f Updated routes in README
Martin Kleppmann authored
98 Edit `config/routes.rb` and add the following (assuming you have a marketing site exposed
99 by a controller called `AboutController`):
100
101 map.logout '/logout', :controller => 'sessions', :action => 'destroy'
102 map.login '/login', :controller => 'sessions', :action => 'new'
103 map.register '/register', :controller => 'users', :action => 'create'
104 map.signup '/signup', :controller => 'customers', :action => 'new'
105 map.welcome '/welcome', :controller => 'customers', :action => 'dashboard'
e2a31bd Inviting users to join customer; resetting forgotten passwords
Martin Kleppmann authored
106 map.forgotten_password '/forgotten_password', :controller => 'users', :action => 'forgotten_password'
107
9c7bcbe Minimal admin interface scaffolding
Martin Kleppmann authored
108 map.resources :customers, :collection => {:welcome => :any, :choose => :get}
109
bd85ff1 Allow admins to become other users
Martin Kleppmann authored
110 map.resources :users, :member => {:impersonate => :any}
986a499 Regenerate fixtures with site key; add routes
Martin Kleppmann authored
111
112 map.resource :session
113
114 # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
115 # For the top-level site we want the about controller, else we want the customers controller
116 #
117 # TODO: would be nicer to patch request_routing to interact with subdomain-fu and allow :subdomain => false
3a28a6f Updated routes in README
Martin Kleppmann authored
118 map.root :controller => "about", :conditions => { :subdomain => nil} # http://localhost/
119 map.root :controller => "about", :conditions => { :subdomain => "example"} # http://example.com/
120 if %w(production development).include? RAILS_ENV
121 map.root :controller => "about", :conditions => { :subdomain => "www"} # http://www.example.com/
122 end
123 map.root :controller => "customers" # customer subdomains
124
125 # Default routes
126 map.connect ':controller/:action/:id'
127 map.connect ':controller/:action/:id.:format'
128
129 # Map tokens to http://example.com/tokencode -- must be the last entry in routes.rb, after default routes
746ff18 Tweaks to login/signup user flow, make more SSL-friendly
Martin Kleppmann authored
130 map.connect ':code', :controller => 'tokens', :action => 'show'
986a499 Regenerate fixtures with site key; add routes
Martin Kleppmann authored
131
132
746ff18 Tweaks to login/signup user flow, make more SSL-friendly
Martin Kleppmann authored
133 Edit `config/environments/production.rb` and add:
4f27e1b Environment settings
Martin Kleppmann authored
134
746ff18 Tweaks to login/signup user flow, make more SSL-friendly
Martin Kleppmann authored
135 # Set this to true if you want the login form to redirect to a https:// URL
136 config.https_login = false
137
138 # Set the base domain name under which our site is hosted
139 config.domain_name = 'example.com'
140
141
142 Edit `config/environtments/development.rb` and add:
143
144 # Do not redirect to HTTPS URLs during development
145 config.https_login = false
146
147 # This name (and several subdomains of it) should be placed in your /etc/hosts, e.g:
148 # 127.0.0.1 example.local www.example.local foo.example.local bar.example.local
149 config.domain_name = 'example.local'
ce65335 Remember requested URL in return_to URL parameter
Martin Kleppmann authored
150
151
152 On your development machine, edit `/etc/hosts` and add a line like:
153
154 127.0.0.1 example.local www.example.local foo.example.local bar.example.local baz.example.local
155
156
157 You may also need to edit `app/models/customer.rb` and add your domain name there
158 (`example` if your full domain name is `example.com`).
d7f0fe0 More route & database config tweaks
Martin Kleppmann authored
159
160
161 Edit `config/database.yml`: add `&TEST` to the line `test:` and append the following two lines:
162
163 cucumber:
164 <<: *TEST
4f27e1b Environment settings
Martin Kleppmann authored
165
166
ce65335 Remember requested URL in return_to URL parameter
Martin Kleppmann authored
167 Then run the tests:
f1de9cd Step-by-step instructions for using this template
Martin Kleppmann authored
168
169 $ rake db:migrate
170 $ rake spec
171 $ rake features
172
173 That should be everything up and running!
bf3c37d Added default application.html.erb
Martin Kleppmann authored
174
175 If your `app/views/layouts` does not yet exist you will get some errors running cucumber
176 (`rake features`). You can fix them by adding a simple `app/views/layouts/application.html.erb`,
177 like the following:
178
179 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
180 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
181 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
182 <head>
183 <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
184 <title>Hello World!</title>
185 </head>
186 <body>
187 <p style="color: green" id="flashNotice"><%= flash[:notice] %></p>
188 <p style="color: red" id="flashError"><%= flash[:error] %></p>
189 <%= yield %>
190 </body>
191 </html>
Something went wrong with that request. Please try again.