实施的OnClick样的功能和格式WRT Rails的局部视图 [英] Implementing a OnClick kind of functionality and formatting wrt Rails Partial-Views

查看:158
本文介绍了实施的OnClick样的功能和格式WRT Rails的局部视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现类似的onclick方法的功能
的Javascript,使用Rails助手。

I am trying to implement a functionality similar to the onclick method of Javascript, using Rails Helpers.

我已经实现了一个自动完成功能的多个字段
Rails的2.0.2和Ruby 1.8.7。该配置在Ubuntu 10.04上运行
是的,我知道..你可能会觉得为什么Rails的2.X当我们的Rails 3.x中,
这是项目的具体目的,是因为。我没有太多的
选择上.. :)。

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.

如果你不能得到一个更好的了解我有什么
实施WRT自动完成,请参考
<一href=\"http://stackoverflow.com/questions/5399991/implementing-auto-complete-for-more-than-one-field-in-rails\">Implementing Rails中自动完成对多个字段

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 .

您还可以得到一个更好的理解我所参照 HTTP实施:/ /imagepaste.nullnetwork.net/viewimage.php?id=2048
http://imagepaste.nullnetwork.net/viewimage.php?id=2050
http://imagepaste.nullnetwork.net/viewimage.php?id=2049

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 .

请注意组特定的配置文件图片的名称是相同的
不同之处在于该峰也必须名.jpg的组标题
追加到它。

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.

我利用一个自定义自动完成的方法,自动完成
插件,也使使用Rails的谐音。该cusotmized汽车
完整的方法,让我修改的基本功能,以适应
我的要求。

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.

来到我的问题,现在说,如果用户输入在文本字段为我
每次,我已经实现了,结果(用于自动完成功能
多于一个找到匹配(即,如果一个以上的组存在哪些
开始填充上的用户的特定搜索查询的I))
接口将拥有所有的以下内容: -

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 :-


  • 集团的具体资料照片(S)出发
    与名称相同的标题,在这种情况下
    我%。JPG

  • 组标题名称。

  • 属于会员总数
    一组

说我有印度和独立作为我的组名称我会得到
下面显示在我的自动完成文本字段的结果。

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)

和类似

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.

如果你不能够得到的图片中你如何在UI的心灵
看起来,请在注册和www.diasp.org搜索任何随机
用户使用其搜索功能,一旦创建帐户。

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.

有关部分的code呈现这一切是: -

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',:身高=>'22':ALIGN =>左%>

  • &LT;%= H inv_group.title
    %>(LT;%= H inv_group.activated_members.size%>)

  •       &LT;%结束%>
        

    '40', :height => '22', :align => 'left' %>

  • <%=h inv_group.title %>(<%=h inv_group.activated_members.size %>)
  • <%end%>

    现在,如果用户将鼠标悬停他/她的鼠标移到说,印度,然后点击它,
    文本字段中填充了 **印度(3)**

    Now if a user hovers his/her mouse over say India and then clicks on it, the text field is populated with **India(3)** .

    我需要的是实现是在点击Rails中这将
    选择只编组标题。我试图执行组标题和
    同组大小不同的&LT;立GT; 标签,我就能够鼠标悬停和
    只选择标题并把它用于填充文本字段。

    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.

    如果我能想出​​如何降低每之间的格式空间
    三title.jpg,所有权和组大小。此选项可能是
    被认为是一种替代修复,但可能不是最好的解决。

    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.

    我也不太清楚我怎么能去差不多的(建议的修复),因为我
    一个新手在WRT RoR的很多东西。我不是什么命令不太清楚
    RoR的我可以利用这将有助于我简化/解决我的任务。能够
    请你帮助我在此。

    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.

    我后来,在某种程度上能够弄清楚,使用JavaScript的
    onclick事件,我可以解决我的问题。我不是太肯定的
    对于相同的使用Rails Helpers.I相当于语法简称
    <一href=\"http://api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptHelper.html#method-i-javascript_tag\" rel=\"nofollow\">http://api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptHelper.html#method-i-javascript_tag
    ,以获得挂起如何javascript_tag可用于我的目的,
    但如果这是出路,我就如何修改真的无能
    基本语法,以满足我的要求。请帮我相同的,如果
    可行的。

    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.

    感谢您..

    推荐答案

    该Script.aculo.us于Ajax.Autocompleter具有只是这样的事情一个简单的功能。你想从自动填充结果中排除任何元素只需要被包裹在一个span.informal标记。所以,你的结果是这样的:

    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:

    <li>
        <span class="informal">[img tag]</span>
        India
        <span class="informal">whatever else</span>
    </li>
    

    当点击了autocompleter的提示列表这样的结果,只有两个字印度将在文本字段中输入。

    When this result is clicked in the autocompleter's hint list, only the word India will be entered in the text field.

    这篇关于实施的OnClick样的功能和格式WRT Rails的局部视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆