我正在尝试设置一个多租户应用程序,但我在这里遇到了这个问题,我无法弄清楚发生了什么。我不断收到此错误。这是我的 routes.rb 我在这里缺少什么。
class SubdomainPresent
def self.matches?(request)
request.subdomain.present?
end
end
class SubdomainBlank
def self.matches?(request)
request.subdomain.blank?
end
end
Rails.application.routes.draw do
resources :contacts
constraints(SubdomainPresent) do
root 'contacts#index', as: :subdomain_root
devise_for :users
resources :users, only: :index
end
constraints(SubdomainBlank) do
root "welcome#index"
resources :accounts, only: [:new, :create]
end
end
这是我的耙子路线
Prefix Verb URI Pattern Controller#Action
contacts GET /contacts(.:format) contacts#index
POST /contacts(.:format) contacts#create
new_contact GET /contacts/new(.:format) contacts#new
edit_contact GET /contacts/:id/edit(.:format) contacts#edit
contact GET /contacts/:id(.:format) contacts#show
PATCH /contacts/:id(.:format) contacts#update
PUT /contacts/:id(.:format) contacts#update
DELETE /contacts/:id(.:format) contacts#destroy
subdomain_root GET / contacts#index
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
user_password PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
POST /users/password(.:format) devise/passwords#create
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
user_registration PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
POST /users(.:format) devise/registrations#create
users GET /users(.:format) users#index
root GET / welcome#index
accounts POST /accounts(.:format) accounts#create
new_account GET /accounts/new(.:format) accounts#new
这是填写的导致错误的表格:
设计/会话/new.html.erb
<h2>Log in</h2>
<%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="form-inputs">
<%= f.input :email, required: false, autofocus: true %>
<%= f.input :password, required: false %>
<%= f.input :remember_me, as: :boolean if devise_mapping.rememberable? %>
</div>
<div class="form-actions">
<%= f.button :submit, "Log in" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
这里也是accounts_controller.rb
class AccountsController < ApplicationController
skip_before_filter :authenticate_user!, only: [:new, :create]
def new
@account = Account.new
@account.build_owner
end
def create
@account = Account.new(account_params)
if @account.valid?
Apartment::Database.create(@account.subdomain)
Apartment::Database.switch(@account.subdomain)
@account.save
redirect_to new_user_session_url(subdomain: @account.subdomain)
else
render action: 'new'
end
end
private
def account_params
params.require(:account).permit(:subdomain, owner_attributes: [:name, :email, :password, :password_confirmation])
end
end