account_subdomain 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +63 -0
  4. data/Rakefile +34 -0
  5. data/app/assets/javascripts/account_subdomain/accounts.js +2 -0
  6. data/app/assets/javascripts/account_subdomain/application.js +13 -0
  7. data/app/assets/stylesheets/account_subdomain/accounts.css +4 -0
  8. data/app/assets/stylesheets/account_subdomain/application.css +13 -0
  9. data/app/controllers/account_subdomain/accounts_controller.rb +49 -0
  10. data/app/controllers/account_subdomain/application_controller.rb +7 -0
  11. data/app/helpers/account_subdomain/accounts_helper.rb +17 -0
  12. data/app/helpers/account_subdomain/application_helper.rb +4 -0
  13. data/app/helpers/account_subdomain/url_helper.rb +16 -0
  14. data/app/models/account_subdomain/account.rb +10 -0
  15. data/app/views/account_subdomain/accounts/_form.html.erb +21 -0
  16. data/app/views/account_subdomain/accounts/index.html.erb +25 -0
  17. data/app/views/account_subdomain/accounts/new.html.erb +5 -0
  18. data/app/views/account_subdomain/accounts/show.html.erb +8 -0
  19. data/app/views/layouts/account_subdomain/application.html.erb +14 -0
  20. data/config/routes.rb +4 -0
  21. data/lib/account_subdomain.rb +15 -0
  22. data/lib/account_subdomain/engine.rb +11 -0
  23. data/lib/account_subdomain/version.rb +3 -0
  24. data/lib/generators/account_subdomain/install_generator.rb +28 -0
  25. data/lib/generators/templates/account_subdomain.rb +27 -0
  26. data/lib/generators/templates/migration.rb +9 -0
  27. data/lib/tasks/account_subdomain_tasks.rake +4 -0
  28. data/test/account_subdomain_test.rb +7 -0
  29. data/test/controllers/account_subdomain/accounts_controller_test.rb +51 -0
  30. data/test/dummy/README.rdoc +28 -0
  31. data/test/dummy/Rakefile +6 -0
  32. data/test/dummy/app/assets/javascripts/application.js +13 -0
  33. data/test/dummy/app/assets/javascripts/users.js +2 -0
  34. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  35. data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
  36. data/test/dummy/app/assets/stylesheets/users.css +4 -0
  37. data/test/dummy/app/controllers/application_controller.rb +6 -0
  38. data/test/dummy/app/controllers/users_controller.rb +59 -0
  39. data/test/dummy/app/helpers/application_helper.rb +2 -0
  40. data/test/dummy/app/helpers/users_helper.rb +2 -0
  41. data/test/dummy/app/models/user.rb +3 -0
  42. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  43. data/test/dummy/app/views/users/_form.html.erb +25 -0
  44. data/test/dummy/app/views/users/edit.html.erb +6 -0
  45. data/test/dummy/app/views/users/index.html.erb +28 -0
  46. data/test/dummy/app/views/users/new.html.erb +5 -0
  47. data/test/dummy/app/views/users/show.html.erb +14 -0
  48. data/test/dummy/bin/bundle +3 -0
  49. data/test/dummy/bin/rails +4 -0
  50. data/test/dummy/bin/rake +4 -0
  51. data/test/dummy/config.ru +4 -0
  52. data/test/dummy/config/application.rb +23 -0
  53. data/test/dummy/config/boot.rb +5 -0
  54. data/test/dummy/config/database.yml +25 -0
  55. data/test/dummy/config/environment.rb +5 -0
  56. data/test/dummy/config/environments/development.rb +29 -0
  57. data/test/dummy/config/environments/production.rb +80 -0
  58. data/test/dummy/config/environments/test.rb +36 -0
  59. data/test/dummy/config/initializers/account_subdomain.rb +5 -0
  60. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  61. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  62. data/test/dummy/config/initializers/inflections.rb +16 -0
  63. data/test/dummy/config/initializers/mime_types.rb +5 -0
  64. data/test/dummy/config/initializers/secret_token.rb +12 -0
  65. data/test/dummy/config/initializers/session_store.rb +3 -0
  66. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  67. data/test/dummy/config/locales/en.yml +23 -0
  68. data/test/dummy/config/routes.rb +7 -0
  69. data/test/dummy/db/development.sqlite3 +0 -0
  70. data/test/dummy/db/migrate/20140912064633_create_users.rb +10 -0
  71. data/test/dummy/db/migrate/20140920121606_create_account_subdomain_accounts.rb +9 -0
  72. data/test/dummy/db/schema.rb +29 -0
  73. data/test/dummy/db/test.sqlite3 +0 -0
  74. data/test/dummy/log/development.log +6631 -0
  75. data/test/dummy/public/404.html +58 -0
  76. data/test/dummy/public/422.html +58 -0
  77. data/test/dummy/public/500.html +57 -0
  78. data/test/dummy/public/favicon.ico +0 -0
  79. data/test/dummy/test/controllers/users_controller_test.rb +49 -0
  80. data/test/dummy/test/fixtures/users.yml +9 -0
  81. data/test/dummy/test/helpers/users_helper_test.rb +4 -0
  82. data/test/dummy/test/models/user_test.rb +7 -0
  83. data/test/dummy/tmp/cache/assets/development/sprockets/0800f54ee19cf3cee10b956fa9786799 +0 -0
  84. data/test/dummy/tmp/cache/assets/development/sprockets/0c0329181a3363da2bcd11252797b755 +0 -0
  85. data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  86. data/test/dummy/tmp/cache/assets/development/sprockets/17e7f32238d11fec6a6cbf29fa85aaf7 +0 -0
  87. data/test/dummy/tmp/cache/assets/development/sprockets/2dafc88a1510883b67ef2ee10f87c949 +0 -0
  88. data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  89. data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  90. data/test/dummy/tmp/cache/assets/development/sprockets/371bf96e99717688ed7313a0c53f4212 +0 -0
  91. data/test/dummy/tmp/cache/assets/development/sprockets/404131fd29f507473a1c43a994b0c0e4 +0 -0
  92. data/test/dummy/tmp/cache/assets/development/sprockets/4050a4e5062ab95c9f32e9b6940821ea +0 -0
  93. data/test/dummy/tmp/cache/assets/development/sprockets/510da110ae528e2d22533be39ff696c5 +0 -0
  94. data/test/dummy/tmp/cache/assets/development/sprockets/545fd3d55a6920ef64aa644a8c96677e +0 -0
  95. data/test/dummy/tmp/cache/assets/development/sprockets/5f1a0d05e77ca8b9a1fc2a47e17a8174 +0 -0
  96. data/test/dummy/tmp/cache/assets/development/sprockets/612b91c67ba90d7fd7705f80419c154b +0 -0
  97. data/test/dummy/tmp/cache/assets/development/sprockets/6e9bf44b62aa4a722191aeb77c8501f7 +0 -0
  98. data/test/dummy/tmp/cache/assets/development/sprockets/6f41a7af67d2a48a8777092b5614b3f8 +0 -0
  99. data/test/dummy/tmp/cache/assets/development/sprockets/6fc757c2c8329244ca95d6909865bbc2 +0 -0
  100. data/test/dummy/tmp/cache/assets/development/sprockets/717de5d3ac12676eb97871f93603998f +0 -0
  101. data/test/dummy/tmp/cache/assets/development/sprockets/7608e445d62cfdf9144c7bcd34cdcb9b +0 -0
  102. data/test/dummy/tmp/cache/assets/development/sprockets/87b209c0c9da28094a8d5581a21262c6 +0 -0
  103. data/test/dummy/tmp/cache/assets/development/sprockets/97c215e1c4f1ed90472115037f06eea9 +0 -0
  104. data/test/dummy/tmp/cache/assets/development/sprockets/a08d9066d13c1b0ffdeb4b5e72430618 +0 -0
  105. data/test/dummy/tmp/cache/assets/development/sprockets/b9d625a779fb8b1e853c316e695b4102 +0 -0
  106. data/test/dummy/tmp/cache/assets/development/sprockets/b9f32bee6b9ed727384329d0ab870061 +0 -0
  107. data/test/dummy/tmp/cache/assets/development/sprockets/cebc6db0bbb8120f430da3970b173d2f +0 -0
  108. data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  109. data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  110. data/test/dummy/tmp/cache/assets/development/sprockets/f53273fd778c49ffd1b612633d95df5e +0 -0
  111. data/test/dummy/tmp/cache/assets/development/sprockets/f56253b5f374fff1a33fbbc9881c9124 +0 -0
  112. data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  113. data/test/fixtures/account_subdomain/accounts.yml +7 -0
  114. data/test/helpers/account_subdomain/accounts_helper_test.rb +6 -0
  115. data/test/integration/navigation_test.rb +10 -0
  116. data/test/models/account_subdomain/account_test.rb +9 -0
  117. data/test/test_helper.rb +15 -0
  118. metadata +278 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b84cd35a4b574ed98471d3bbe1ada6b9f4b6240e
4
+ data.tar.gz: cda69e55af3a7b72e8e24ad31dde95185f5c21b6
5
+ SHA512:
6
+ metadata.gz: 51bce02935b0e8d2c00c5ca04dd4d4901809e58301fa44643d0967889953edfab4fb90d29c99c144f661f20e7b5c910ccffa1a84930f3aa30a74642fb8d1187a
7
+ data.tar.gz: a53b3ac733b6d5221b3523dfd69625dbb52f4a03ffa1196fe369c5b82ce9f93c35c03babb529d19197a9bfba33604f28d29da09c81538a02696a61068f2da46e
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,63 @@
1
+ # AccountSubdomain
2
+
3
+ Adds the subdomain functionality to rails application. Ready for rails 4([RubyGems](http://rubygems.org/gems/account_subdomain))
4
+
5
+ ### Dummy Application
6
+
7
+ * [spec/dummy_app](https://github.com/sachin/account_subdomain/tree/master/test/dummy)
8
+
9
+ ## Install
10
+
11
+ **Gemfile** (Rails 4)
12
+
13
+ ```
14
+ gem 'account_subdomain'
15
+ ```
16
+
17
+ **Console**
18
+
19
+ ```
20
+ bundle
21
+ ```
22
+
23
+ ```
24
+ rails generate account_subdomain:install
25
+ ```
26
+
27
+ ```
28
+ rake db:migrate
29
+ ```
30
+ ### Extend your Routes for mount ACCOUNT SUBDOMAIN
31
+
32
+ ```
33
+ mount AccountSubdomain::Engine => "/account_subdomain"
34
+ ```
35
+
36
+ You are done !
37
+
38
+ ## Usage
39
+
40
+ Account subdomain gem add the functionality of adding and managing the subdomain functionality in rails application.
41
+
42
+ It gives you some filters and ui helpers
43
+ ### subdomain
44
+ It return the subdomain from the request object
45
+
46
+ ### validate_subdomain
47
+ It validated the request subdomain. If subdomain not found then return to the redirect url mentioned in account_subdomain.rb under initializers.
48
+
49
+ ### current_subdomain
50
+ Return the valid subdomain else nil.
51
+
52
+ ## Settings
53
+ Setting for account subdomain mentioned in account_subdomain.rb under initializers
54
+
55
+ ## UI Helper
56
+
57
+ ### url_for
58
+
59
+ We override the default url_for helper now it supports the subdomain option to generate the url. example:-
60
+
61
+ articles_url(:subdomain => 'test') #=> test.example.com/articles
62
+
63
+ article_url(article, :subdomain => 'test') #=> test.example.com/articles/1
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'AccountSubdomain'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,49 @@
1
+ #require_dependency "account_subdomain/application_controller"
2
+
3
+ module AccountSubdomain
4
+ class AccountsController < ApplicationController
5
+ before_action :set_account, only: [:show, :destroy]
6
+
7
+ # GET /accounts
8
+ def index
9
+ @accounts = AccountSubdomain::Account.all
10
+ end
11
+
12
+ # GET /accounts/1
13
+ def show
14
+ end
15
+
16
+ # GET /accounts/new
17
+ def new
18
+ @account = AccountSubdomain::Account.new
19
+ end
20
+
21
+ # POST /accounts
22
+ def create
23
+ @account = AccountSubdomain::Account.new(account_params)
24
+
25
+ if @account.save
26
+ redirect_to main_app.root_url(:subdomain => @account.subdomain), notice: 'Account was successfully created.'
27
+ else
28
+ render action: 'new'
29
+ end
30
+ end
31
+
32
+ # DELETE /accounts/1
33
+ def destroy
34
+ @account.destroy
35
+ redirect_to accounts_url, notice: 'Account was successfully destroyed.'
36
+ end
37
+
38
+ private
39
+ # Use callbacks to share common setup or constraints between actions.
40
+ def set_account
41
+ @account = AccountSubdomain::Account.find(params[:id])
42
+ end
43
+
44
+ # Only allow a trusted parameter "white list" through.
45
+ def account_params
46
+ params.require(:account).permit(:subdomain)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,7 @@
1
+ class AccountSubdomain::ApplicationController < ApplicationController
2
+ AccountSubdomain.action_controller_filters.each_pair do|key, reflection|
3
+ reflection.each do|_rel|
4
+ self.class_eval "#{key} :#{_rel.to_sym}"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ module AccountSubdomain
2
+ module AccountsHelper
3
+
4
+ def subdomain
5
+ request.subdomain(AccountSubdomain.tld_length)
6
+ end
7
+
8
+ def validate_subdomain
9
+ redirect_to eval("main_app.#{AccountSubdomain.redirect_path}"), :error => 'You are not authorized.' unless current_subdomain.present?
10
+ end
11
+
12
+ def current_subdomain
13
+ @subdomain ||= AccountSubdomain::Account.find_by_subdomain(subdomain)
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ module AccountSubdomain
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,16 @@
1
+ module AccountSubdomain
2
+ module UrlHelper
3
+ def with_subdomain(subdomain)
4
+ subdomain = (subdomain || "")
5
+ subdomain += '.' unless subdomain.empty?
6
+ [subdomain, request.domain(AccountSubdomain.tld_length), request.port_string].join
7
+ end
8
+
9
+ def url_for(options = nil)
10
+ if options.kind_of?(Hash) && options.has_key?(:subdomain)
11
+ options[:host] = with_subdomain(options.delete(:subdomain))
12
+ end
13
+ super
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ module AccountSubdomain
2
+ class Account < ActiveRecord::Base
3
+ validates :subdomain, :presence => true, uniqueness: {message: 'already been taken.'}
4
+ AccountSubdomain.reflections.each_pair do|key, reflection|
5
+ reflection.each do|_rel|
6
+ self.class_eval "#{key} :#{_rel.to_sym}, class_name: '#{_rel.classify.to_sym}'"
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,21 @@
1
+ <%= form_for(@account) do |f| %>
2
+ <% if @account.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@account.errors.count, "error") %> prohibited this account from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @account.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :subdomain %><br>
16
+ <%= f.text_field :subdomain %>
17
+ </div>
18
+ <div class="actions">
19
+ <%= f.submit %>
20
+ </div>
21
+ <% end %>
@@ -0,0 +1,25 @@
1
+ <h1>Listing accounts</h1>
2
+
3
+ <table>
4
+ <thead>
5
+ <tr>
6
+ <th>Subdomain</th>
7
+ <th></th>
8
+ <th></th>
9
+ </tr>
10
+ </thead>
11
+
12
+ <tbody>
13
+ <% @accounts.each do |account| %>
14
+ <tr>
15
+ <td><%= account.subdomain %></td>
16
+ <td><%= link_to 'Show', account %></td>
17
+ <td><%= link_to 'Destroy', account, method: :delete, data: { confirm: 'Are you sure?' } %></td>
18
+ </tr>
19
+ <% end %>
20
+ </tbody>
21
+ </table>
22
+
23
+ <br>
24
+
25
+ <%= link_to 'New Account', new_account_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New account</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', accounts_path %>
@@ -0,0 +1,8 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <strong>Subdomain:</strong>
5
+ <%= @account.subdomain %>
6
+ </p>
7
+
8
+ <%= link_to 'Back', accounts_path %>
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>AccountSubdomain</title>
5
+ <%= stylesheet_link_tag "account_subdomain/application", media: "all" %>
6
+ <%= javascript_include_tag "account_subdomain/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,4 @@
1
+ AccountSubdomain::Engine.routes.draw do
2
+ resources :accounts, :except => [:edit, :update]
3
+ root to: 'accounts#new'
4
+ end
@@ -0,0 +1,15 @@
1
+ require "account_subdomain/engine"
2
+
3
+ module AccountSubdomain
4
+ mattr_accessor :reflections
5
+ @@reflections = {}
6
+
7
+ mattr_accessor :redirect_path
8
+ @@redirect_path = '/'
9
+
10
+ mattr_accessor :tld_length
11
+ @@tld_length = 1
12
+
13
+ mattr_accessor :action_controller_filters
14
+ @@action_controller_filters = {}
15
+ end
@@ -0,0 +1,11 @@
1
+ module AccountSubdomain
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace AccountSubdomain
4
+ initializer "account_subdomain.load_helpers" do
5
+ ActiveSupport.on_load(:action_controller) do
6
+ include AccountSubdomain::AccountsHelper
7
+ helper AccountSubdomain::Engine.helpers
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module AccountSubdomain
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,28 @@
1
+ module AccountSubdomain
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("../../templates", __FILE__)
5
+ include Rails::Generators::Migration
6
+
7
+ desc "Creates a AccountSubdomain initializer."
8
+ def copy_initializer
9
+ template "account_subdomain.rb", "config/initializers/account_subdomain.rb"
10
+ end
11
+
12
+ #desc "Creates a url helper."
13
+ #def copy_url_helper
14
+ # template "url_helper.rb", "app/helpers/url_helper.rb"
15
+ #end
16
+
17
+ def copy_account_subdomain_migration
18
+ migration_template 'migration.rb', 'db/migrate/create_account_subdomain_accounts.rb'
19
+ end
20
+
21
+ # Implement the required interface for Rails::Generators::Migration.
22
+ def self.next_migration_number(dirname)
23
+ next_migration_number = current_migration_number(dirname) + 1
24
+ ActiveRecord::Migration.next_migration_number(next_migration_number)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ #Add the relationships in the Account Subdomain models.
2
+ #like if account subdomain has many users
3
+ #you can give that AccountSubdomain.reflections[:has_many] = ['users']
4
+ #You can give an array to each type of relationships.
5
+ #
6
+ #AccountSubdomain supports every type of relationships which rails supports
7
+ AccountSubdomain.reflections[:has_many] = ['users']
8
+ AccountSubdomain.reflections[:has_one] = []
9
+ AccountSubdomain.reflections[:belongs_to] = []
10
+
11
+ #This setting is used for redirect for invalid subdomain.
12
+ AccountSubdomain.redirect_path = 'account_subdomain_path'
13
+
14
+ #This setting is for domain tld
15
+ # tdd for
16
+ #example.com => #1
17
+ #example.co.in => #2
18
+ #set it as per your domain name
19
+ AccountSubdomain.tld_length = 1
20
+
21
+
22
+ #Settings for filters
23
+ #use case :- You want the https authentication before the access the account subdomain
24
+ #AccountSubdomain.action_controller_filters[:before_filter] = [:validate_http_access_only]
25
+ #
26
+ # Add validate_http_access_only filter in your application.rb
27
+ AccountSubdomain.action_controller_filters[:before_filter] = []