Philippe Haumesser
Philippe Haumesser

Reputation: 647

Rails Apartment Tenant LocalJumpError switch

I m creating a tenant when I click on a button in a view. The tenant is well create but when I try to switch to this tenant just after I have this error: LocalJumpError in EntreprisesController#create_tenant - no block given (yield). Thanks for any help

My controller:

# creation du tenant dans apartement
  def create_tenant
    Apartment::Tenant.create(params[:id])
    Apartment::Tenant.switch(params[:id])
 #   redirect_to entreprise_path(enterprise_id: params[:entreprise])
  end

My view:

  <div class="col-md-2">
          <%= link_to "add new tenant", create_tenant_entreprise_path(id: entreprise.subdmain), method: :post  %>
        </div>

Upvotes: 0

Views: 408

Answers (1)

estani
estani

Reputation: 26487

You don't need the switch at all, just redirect to the proper url.

If you have set a subdomain apartment, then you have to redirect to that subdomain. Apartment elevator will do the switch automatically from the url as is always the case.

switch is meant to be used with a block. There's a switch! that might work in your case too, but this is not the way to go unless you have some very specific edge case, which I honestly can't think of.

Upvotes: 2

Related Questions