处理标准用户面临的场景
*我想知道我是否可以在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常你会为此使用助手。您可以根据您的示例编写名为
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) orfollow_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.