实现 OnClick 类型的功能并格式化 Rails 部分视图
我正在尝试实现类似于 onclick 方法的功能 Javascript,使用 Rails Helpers。
我已经为多个字段实现了自动完成功能 Rails 2.0.2 和 Ruby 1.8.7。此配置在Ubuntu 10.04上运行 是的,我知道......你可能会觉得当我们有 Rails 3.x 时为什么还要使用 Rails 2.x , 之所以如此,是因为项目的特定目的。我没有太多的 对此的选择..:)。
我能够成功检索一组特定的个人资料图片,一组 标题和属于基于组的成员总数 给定的“标题”作为用户在中输入的基本搜索查询 正在执行自动完成功能的文本字段。得到 适用于上述场景的自动完成功能是 挑战本身。
如果您无法更好地理解我所拥有的内容 实现了wrt自动完成功能,请参考 在 Rails 中实现多个字段的自动完成 。
您还可以通过参考 http://imagepaste 更好地理解我所实现的内容.nullnetwork.net/viewimage.php?id=2048 , http://imagepaste.nullnetwork.net/viewimage.php?id=2050 和 http://imagepaste.nullnetwork.net/viewimage.php?id=2049。
请注意团体特定个人资料图片的名称与 组标题,但图片也有 .jpg 附加到它。
我正在使用自定义的自动完成方法,自动完成 插件并使用 Rails 部分。定制汽车 完整的方法允许我修改基本功能以适应 我的要求。
回到我的问题,现在假设用户在文本字段中输入“I” 根据我已经实现的自动完成功能,结果(对于 找到多个匹配项(即如果存在多个组 以“I”开头)在特定搜索查询上)填充在用户上 界面将具有以下所有内容:-
- 组特定个人资料图片开始 在本例中,名称与标题相同 "I%".jpg
- 组标题名称。
- 所属会员总数 一个团体
假设我将印度和独立作为我的团体名称,我将获得 以下结果显示在我的自动完成文本字段中。
India.jpg(image will be displayed) India(Group title name displayed) 3(dummy value here)
同样,
Independence.jpg Independence
4
所有这些都将出现在一个文本字段中。请注意中的评论 括号不是通过自动完成返回的结果的一部分。
如果您无法想象 UI 的效果 会看,请在 www.diasp.org 注册并搜索任何随机 创建帐户后,用户将使用其搜索功能。
请注意图像、标题名称和总数之间的间距 小组成员人数过多。我将在以下内容中提到这一点 以下评论。
呈现所有这些的部分代码是:-
<ul>
<% for inv_group in @investor_group2 %>
<%=image_tag "investor_groups/#{inv_group.title}.jpg" , :width =>
'40', :height => '22',:对齐=> '左'%>
现在,如果用户将鼠标悬停在印度上,然后单击它, 文本字段填充 **India(3)**
。
我需要的是实现点击 Rails 它将 仅选择群组标题。我尝试实现组标题并 具有单独的
标签的组大小,然后我可以将鼠标悬停并 仅选择标题并将其填充到文本字段中。这种方法的问题是它完全破坏了格式 以及图像、标题和组大小之间的间距/间隙。 这需要格式化以获得更好的外观和感觉 用户界面。
如果我能弄清楚如何减少每个之间的格式空间 三个title.jpg,标题和组大小。这个选项可以是 被认为是替代修复,但可能不是最佳修复。
我不太确定我怎样才能像我一样(建议的修复) 一个新手在 RoR 中遇到了很多事情。我不太确定什么命令 我可以利用 RoR 来帮助我简化/解决我的任务。能 请你帮我解决这个问题。
我也将不胜感激任何有关更有效修复的建议 这个场景。
后来我在某种程度上能够通过使用 javascript 弄清楚这一点 onclick 事件,我可以解决我的问题。我不太确定 使用 Rails Helpers.I 提到的相同语法 http://api.rubyonrails.org/classes/ ActionView/Helpers/JavaScriptHelper.html#method-i-javascript_tag ,了解如何使用 javascript_tag 来达到我的目的, 但如果这是出路,我真的不知道如何修改 满足我的要求的基本语法。请帮助我同样的如果 可行的。
谢谢..
I am trying to implement a functionality similar to the onclick method
of Javascript, using Rails Helpers.
I have implemented a auto complete feature for more than one field in
Rails 2.0.2 and Ruby 1.8.7. This configuration is run on Ubuntu 10.04
and yes , I know.. you might feel why Rails 2.x when we have Rails 3.x ,
it is so because of project specific purposes. I don't have much of a
choice on that ..:) .
I am able to successfully retrieve a group specific profile pic, a group
title and a the total number of members belonging to a group based on
the given "title" as the basic search query that a user inputs in the
text field where auto complete functionality is being performed. Getting
the auto complete functionality to work for the scenario above was a
challenge in itself.
In case you aren't able to get a better understanding of what I have
implemented wrt autocomplete, kindly refer to
Implementing auto complete for more than one field in Rails
.
You can also get a better understanding of what I have implemented by referring to http://imagepaste.nullnetwork.net/viewimage.php?id=2048 ,
http://imagepaste.nullnetwork.net/viewimage.php?id=2050
and http://imagepaste.nullnetwork.net/viewimage.php?id=2049 .
Please note the name of group specific profile pic is same as that of
the group title with the exception that the pic would also have .jpg
appended to it.
I am making use of a customized auto complete method, an auto complete
plugin and also making use of Rails partials. The cusotmized auto
complete method is allowing me to modify the basic functionality to suit
my requirement.
Coming to my question, Now say if a user enters "I" in the text field as
per the auto complete feature that I have implemented, the results(for
more than one matches found(i.e. if more than one group exists which
start with an "I") on a specific search query) populated on the User
Interface would have all the following :-
- Group Specific Profile Pic(s) starting
with name same as title, in this case
"I%".jpg - Group title name.
- Total number of members belonging to
a group
Say I have India and Independence as my group names I would obtain the
following results displayed in my auto complete text field.
India.jpg(image will be displayed) India(Group title name displayed) 3(dummy value here)
and similarly
Independence.jpg Independence
4
All this would come in one text field. Please note the comments in
parentheses are not part of the results returned via auto complete.
In case you are not able to get the picture in your mind of how the UI
would look, Kindly register in www.diasp.org and search for any random
user using its search feature , once your account is created.
Please observe that the spacing between image, title name and total
number of group members is too much. I will be referring back to this in
the comments that follow.
The code for the partial that renders all this is:-
<ul>
<% for inv_group in @investor_group2 %>
<%=image_tag "investor_groups/#{inv_group.title}.jpg" , :width =>
'40', :height => '22', :align => 'left' %>
%>(<%=h inv_group.activated_members.size %>)
<%end%>
Now if a user hovers his/her mouse over say India and then clicks on it,
the text field is populated with **India(3)**
.
What I need is to implement is a on click in Rails which will
select only Group title. I tried to implement the group title and
group size with separate <li>
tags , I was then able to mouseover and
select only the title and get it populated for the text field.
The problem with this approach is it completely spoils the formatting
and the spacings/gaps between the image, the title and the group size.
This requires formatting in order to obtain a better look and feel of
the UI.
If I can figure out how to reduce the formatting space between each of
the three title.jpg,title and group size. This option could be
considered to be an alternative fix but might not be the best fix.
I am not too sure how can I go about the same(the suggested fix) as I am
a newbie wrt many things in RoR. I am not too sure on what commands of
RoR I can make use of which would help me simplify/solve my task. Can
you please help me on this.
I would be also grateful for any suggestions on a more efficient fix to
this scenario.
I later on, in a way was able to figure out that by using javascript's
onclick event, I could solve my problem. I am not too sure about the
equivalent syntax for the same using Rails Helpers.I referred to
http://api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptHelper.html#method-i-javascript_tag
, to get a hang of how the javascript_tag can be used for my purpose,
but if this is the way out, I am really clueless on how to modify the
basic syntax to suit my requirements. Kindly help me with the same if
feasible.
Thank you..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Script.aculo.us Ajax.Autocompleter 有一个针对此类事情的简单功能。您想要从自动填充结果中排除的任何元素只需要包装在 span.informal 标记中。因此,您的结果将如下所示:
在自动完成程序的提示列表中单击此结果时,只会在文本字段中输入单词 India。
The Script.aculo.us Ajax.Autocompleter has a simple feature for just this sort of thing. Any element that you want to exclude from the auto-populated results just needs to be wrapped in a span.informal tag. So your results would look like this:
When this result is clicked in the autocompleter's hint list, only the word India will be entered in the text field.
添加来自 http://www.ruby-forum.com/topic 的 Walter 建议/1475454?reply_to=992312 。
下面的代码对我来说很神奇......
在我的 groups.css 中我添加了以下内容:-
感谢您的建议 Walter,我知道我可能不完全遵循 HTML 标记标准(我还有很多基础要涵盖)强化我的 HTML 概念..)。但我很高兴最终这根据要求起作用了。
再次感谢..沃尔特..
To add to Walter's suggestion from http://www.ruby-forum.com/topic/1475454?reply_to=992312 .
This code below did the magic for me...
and in my groups.css I added the following:-
Thanks for your suggestion Walter, I know I might not be exactly following HTML Markup standards( I have still a lot ground to cover to strengthen my concepts in HTML.. ). But I am just happy that finally this works based on the requirement.
Thanks again.. Walter..