处理标准用户面临的场景

发布于 2024-09-18 15:37:37 字数 332 浏览 0 评论 0原文

*我想知道我是否可以在 javascript 中完成所有这些操作,而不是使用 Rails 助手

在我的应用程序中,有几种类型的“if-else”UI 案例。这是一个相当常见的场景,我想知道是否有人有一个简洁的方法来做到这一点?

EG 1) 可能有多种类型的链接具有相同的行为:“upvote”等。

如果是用户自己的文章,不希望传到服务器,而是弹出一个对话框

EG 2) 可能有几个名为“关注”、“成为粉丝”等的链接

如果用户之前已经完成了给定的操作,则它应该是“已关注”文本而不是链接。

*I was wondering if i could do all these in javascript, as opposed to having rails helpers

In my application, there are several types of "if-else" UI cases. This is a fairly common scenario, and i wonder if anyone has a tidy way to do these?

EG 1) There might be several types of links with the same behavior: "upvote", etc.

If it is the user's own article, i do not want it to be passed to the server, but pop up a dialog box

EG 2) There might be a several links called "follow", "become a fan", etc

If the user already have done the given action before, it should be a text "followed" instead of a link.

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

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

发布评论

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

评论(1

孤者何惧 2024-09-25 15:37:37

通常你会为此使用助手。您可以根据您的示例编写名为 upvote_button (可能将用户作为参数)或 follow_button 的帮助程序(对于已经关注的用户,该帮助程序可能采用 true/false /不-以下。

如果您可以更具体地说明您需要什么,我的回答可能会更具体。

Normally you'd use helpers for this. You write helpers called, based on your examples, upvote_button (which might take a user as a parameter) or follow_button (where this one might take true/false for already-following/not-following.

If you can be more specific as to what you need, I can probably be more specific in my answer.

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