0

I am trying to set up a multi tenancy app and i am having this issue here and i can not figure out what is going on. i keep getting this error. here is my routes.rb what am I missing here.

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

Here is my rake routes

                  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

This is the form that gets filled out which leads to the error:

sign up form

devise/sessions/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" %>

error screen

also here is the 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
Eyeslandic
  • 14,553
  • 13
  • 41
  • 54
  • Is your constraint being successful? I.E. are you signing in using a subdomain? – Brennan Feb 10 '17 at 18:57
  • if i type in a subdomain it works fine. but the main page has no subdomain. the user goes on creates an account with the subdomain and when it gets submitted thats when i get the error. there seems to be some sort of redirect error im guessing but really dont know... – FunkyJamma Feb 10 '17 at 19:00
  • really silly one: you do restart the server each time you change routes.rb? Routes.rb gets interpretated only once when the server is started. – thiebo Feb 10 '17 at 19:08
  • also, I don't see a method `new` in the code you posted. Rails is looking for the method `new` in `devise/sessions ` – thiebo Feb 10 '17 at 19:10
  • Yes I do restart the server everytime I make changes. I have the new.html.erb in devise/sessions I added it to my main post – FunkyJamma Feb 10 '17 at 19:48
  • Do you generate devise controlller? It seems that you are missing devise controller – Weibo Chen Feb 11 '17 at 01:58

0 Answers0