在 Rails 应用程序中配置路线

发布于 2024-10-29 11:37:53 字数 109 浏览 3 评论 0 原文

您好,

我为我的应用程序创建了一个自定义索引页面,其中有两个图像链接,一个用于用户,另一个用于管理员。我该如何在routes.rb中配置路由,以便链接到达专用页面。

谢谢。

HI,

I have created a custom index page for my application , which has two image links , one for users and other for admin. How shall I configure the routes in the routes.rb, so that the links take to the dedicated pages.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

可是我不能没有你 2024-11-05 11:37:53

可以在模板中创建条件:

<% if @currentUser.isAdmin %>
....
# image link one
....

<% else %>
....
# image link two
....
<% end %>

May be create condition in the template:

<% if @currentUser.isAdmin %>
....
# image link one
....

<% else %>
....
# image link two
....
<% end %>
和我恋爱吧 2024-11-05 11:37:53

如果你有两个控制器,比如管理员和用户,你可以在你的路由

resources :admins
resources :users

和索引视图中写一些类似的内容,

<%= link_to 'admins', admins_path %>
<%= link_to 'users', users_path %>

以获取有关路由和 Rails 的更多信息,一般请阅读可用的 Rails 指南 此处

if you have two controllers, say Admins and Users, you could say in your routes

resources :admins
resources :users

and in your index view write something like

<%= link_to 'admins', admins_path %>
<%= link_to 'users', users_path %>

for more about routing and rails in general please read the rails guides available here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文