ruby создает ошибку арендатора квартиры в маршрутизаторе.

Это мое сообщение об ошибке: маршрут не соответствует [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

и мое мнение - list.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>

person Philippe Haumesser    schedule 19.07.2018    source источник


Ответы (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.

person Mehmet Adil İstikbal    schedule 19.07.2018