Rails 5.1使用apartment gem

时间:2018-02-09 22:18:28

标签: ruby-on-rails ruby-on-rails-5 apartment-gem

似乎无法让它发挥作用。我使用Apartment Gem和Devise并尝试在sign_in之后重定向到用户子域。当用户首次注册时,他们将被转移到他们的子域;一旦退出并再次登录,我似乎无法让它工作。

application_controller.rb 这不起作用

...
protected
def after_sign_in_path_for(resource)
  return root_url(subdomain: current_user.subdomain)
end
...

但这会将我转移到current_user id(http://3.lvh.me:3000

...
def after_sign_in_path_for(resource)
  return root_url(subdomain: current_user)
end
...

所以我知道我走在正确的轨道上。我尝试了多种变化,而不是我记得尝试将其转移到(http://subdomain.lvh.me:3000

我不确定要在此处包含哪些代码,但我们将从我的控制器开始创建代码,该代码会在注册后将用户重定向到子域名 - 希望这会激发一些想法。

accounts_controller.rb

...
def create
  @account = Account.new(account_params)
  if @account.save
    @account.create_schema
    sign_in(@account.owner)
    flash[:notice] = 'Your account has been created.'
    redirect_to root_url(subdomain: @account.subdomain)
  else
    flash.now[:alert] = 'Sorry, your account could not be created.'
    render :new
  end
end
...

0 个答案:

没有答案
相关问题