简体   繁体   English

如何在Rails / Devise中为合作伙伴链接创建自定义登录页面URL?

[英]How can I create custom login page URLs in Rails/Devise for partner links?

I have a Rails 4 application using Devise for authentication. 我有一个使用Devise进行身份验证的Rails 4应用程序。

In addition to the standard Devise login page, I want to have partner login pages that basically look and function the same way, but have a unique URL, like: 除了标准的Devise登录页面之外,我还希望合作伙伴登录页面的外观和功能基本相同,但是具有唯一的URL,例如:

http://example.com/partner1 http://example.com/partner1

What is the best way to do this? 做这个的最好方式是什么? I'm not sure how the routes file should look. 我不确定路由文件的外观。 And is using FriendlyID a good idea as well? 使用FriendlyID也是一个好主意吗?

I have a PartnerPage model in the database which contains a "link" field, which is where the admin will enter the link/partner code. 我在数据库中有一个PartnerPage模型,其中包含一个“链接”字段,管理员将在其中输入链接/合作伙伴代码。

Creating a custom route to the signup form is pretty straight forward: 为注册表单创建自定义路线非常简单:

get '/partner1', to: 'devise/sessions#new'

However if you want to have a customized login screen a good solution is to subclass Devise::SessionsController . 但是,如果您想拥有一个自定义的登录屏幕,一个很好的解决方案是将Devise::SessionsController子类化。

# app/controllers/partner1/sessions_controller.rb
class Partner1::SessionsController < Devise::SessionsController; end

and in your routes: 在您的路线上:

get '/partner1', to: 'partner1/sessions#new'

This will render app/veiws/partner1/sessions/new.html.erb . 这将呈现app/veiws/partner1/sessions/new.html.erb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM