How to implement this nested linked_to_function?

一笑奈何 提交于 2019-12-13 08:26:09

问题


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'

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}\")"

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

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.

This project is still using Rails 2.3. What is a better way to implement this?


回答1:


My problem was solved using the answer in page.insert_html does not insert html with link_to_function (rails) by "Jose"

The code provided in the answer was put in rails/lib/rails_ext.rb



来源:https://stackoverflow.com/questions/16361408/how-to-implement-this-nested-linked-to-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!