如何实现此嵌套的linked_to_function? [英] How to implement this nested linked_to_function?
问题描述
在我看来,我希望用户能够浏览产品目录.层次结构如下:
In my view I want the user to be able to browse a catalog of products. The hierarchy is as following:
Category
Product
AdditionalInfoForm
在主视图中,我为类别渲染了部分图像:
In my main view I render a partial for the categories:
#opContent
= render :partial => 'op_main_categories'
op_main_categories部分定义如下:
The op_main_categories partial is defined as following:
- @controller.getPortalCategories.each do |c|
= link_to_function "#{c.name}", :class => 'opCategoryHeaderText' do |page|
- partial = escape_javascript(render :partial => 'op_secondary_categories', :locals => { :c => c })
- page << "$('opContent').update(\"#{partial}\")"
当用户单击以上部分中的链接时,将通过op_secondary_categories部分来呈现产品:
When the user clicks a link in the above partial, the products are rendered by means of the op_secondary_categories partial:
- @controller.getPortalProductsForCategory(c).each do |p|
= link_to_function "#{p.name}", :class => 'opCategoryHeaderText' do |page|
- partial = escape_javascript(render :partial => 'op_did_line', :locals => { :p => p })
- page << "$('opContent').update(\"#{partial}\")"
op_did_line现在是纯文本:
op_did_line is plain text for now:
%p Yes, this is form! Hello?
此设置将生成以下链接(针对一个类别):
This setup will generate the following link (for one category):
<a class="opCategoryHeaderText" onclick="$('opContent').update("<a class=\"opCategoryHeaderText\" href=\"#\" onclick=\"$(\'opContent\').update("<p>Yes, this is form! Hello?</p>\n"); return false;\">IPSDN + PVC 3yr<\/a>\n<a class=\"opCategoryHeaderText\" href=\"#\" onclick=\"$(\'opContent\').update("<p>Yes, this is form! Hello?</p>\n"); return false;\">PVC<\/a>\n"); return false;" href="#">PVC</a>
添加第二层link_to_function会破坏所有代码.我不再能够浏览层次结构.当仅存在一个link_to_function时,我可以浏览.
Adding the second tier of link_to_function breaks all of the code. I am no longer able to browse the hierarchy. When there is only one link_to_function present, I can browse.
该项目仍在使用Rails 2.3.有什么更好的方法来实现呢?
This project is still using Rails 2.3. What is a better way to implement this?
推荐答案
答案中提供的代码已放入rails/lib/rails_ext.rb
The code provided in the answer was put in rails/lib/rails_ext.rb
这篇关于如何实现此嵌套的linked_to_function?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!