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