这是我的错误消息:没有路由与[GET]“ / entreprises / 10 / create_tenant”匹配
当您列出自己的企业时,我试图允许创建一个租户(宝石公寓)。
在企业模型中,有一个名为subdmain的属性,应该用作租户名称。
感谢您的帮助。
我的路由器是
class SubdmainConstraint
def self.matches?(request)
subdmains = %w{ www admin public test }
request.subdmain.present? && !subdmains.include?(request.subdmain)
end
end
Rails.application.routes.draw do
constraints SubdmainConstraint do
end
get 'layouts/confirmed'
get 'pages/home'
get 'entreprises/listing'
namespace :admin do
resources :users
root to: "users#index"
end
devise_for :users, :controllers => { registrations: 'registrations', confirmations: 'confirmations'}
resources :users
resources :entreprises do
post 'hide_case', on: :member
post 'unhide_case', on: :member
post 'create_tenant', on: :member
end
root to: "pages#home"
我的企业控制者是
class EntreprisesController < ApplicationController
before_action :authenticate_user!
before_action :set_entreprise, only: [:edit, :update]
before_action :require_same_user, :only => [:update]
def index
@entreprises = current_user.entreprises
end
def new
@entreprise = current_user.entreprises.build
end
def create
@entreprise = current_user.entreprises.build(entreprise_params)
@entreprise.owner_id = current_user.id
if @entreprise.save
redirect_to entreprise_listing_path, flash[:notice] = "Saved..."
else
flash[:alert] = "Something went wrong...#{@entreprise.errors.full_messages.join('. ')}"
render :new
end
end
def listing
@entreprises = Entreprise.where(:owner_id => current_user.id)
end
def show
@entreprises = current_user.entreprises
end
def update
if @entreprise.update(entreprise_params)
flash[:notice] = "Saved..."
else
flash[:alert] = "Something went wrong...#{@entreprise.errors.full_messages.join('. ')}"
end
redirect_back(fallback_location: request.referer)
end
def hide_case
@case = Entreprise.find(params[:id])
@case.update(active_entrerpise: true)
redirect_to entreprises_listing_path
end
def unhide_case
@case = Entreprise.find(params[:id])
@case.update(active_entrerpise: false)
redirect_to entreprises_listing_path
end
def create_tenant
Apartment::Tenant.create(subdmain)
redirect_to entreprise_path(params[:entreprise])
end
我的视图是企业文件夹中的listing.html.erb:
<h2> VOTRE LISTING DES ENTREPRISES </h2>
<div class="row">
<div class="panel-body">
<% @entreprises.each do |entreprise| %>
<div class="row">
<div class="col-md-5">
<h4><%= link_to entreprise.name_entreprise, edit_entreprise_path(entreprise) %></h4>
</div>
<div class="col-md-2">
<%= link_to "add new tenant", create_tenant_entreprise_path(id: entreprise.id) %>
</div>
<div>
<% if entreprise.active_entrerpise? %>
<%= button_to "Unactivate", unhide_case_entreprise_path(id: entreprise.id), class: "btn btn-normal" %>
<% else %>
<%= button_to "Activate", hide_case_entreprise_path(id: entreprise.id), class: "btn btn-normal" %>
<% end %>
</div>
</div>
<% end %>
</div>
</div>
答案 0 :(得分:1)
我认为您应该将此行<%= link_to "add new tenant", create_tenant_entreprise_path(id: entreprise.id) %>
更改为<%= link_to "add new tenant", create_tenant_entreprise_path(id: entreprise.id), method: :post %>
您正在发送GET
而不是POST
的请求。