Guest User

Untitled

a guest
Feb 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. <%= error_messages_for 'category' %>
  2.  
  3. <!--[form:category] Jowy
  4. <p><label for="category_name">Name</label><br/>
  5. <%= text_field 'category', 'name' %></p>
  6. <p><label for="category_parent_id">Parent Category</label><br/>
  7. <%= render :partial => 'category_select', :locals => {:id => "category_parent_id"} %></p>
  8. <div id="box"></div>
  9.  
  10. <%= javascript_tag("$('category_parent_id').onchange = function(){"+remote_function(:update => :box,:url => {:action => :root_change}, :with => "'id='+$F('category_parent_id')")+"}") %>
  11.  
  12. <!--[eoform:category]-->
  13.  
  14. <!--[form:photo]-->
  15.  
  16. -----------------------------------------------------------------------------------------------------
  17. ** from _category_select.rhtml partial **
  18. <%= collection_select(:category, :parent_id,
  19. @all_categories, :id, :name,{},{:size => 5, :multiple => "multiple", :id => id, :name => id}) %>
  20. <%= javascript_tag("$('"+id+"').onchange = function(){" + remote_function(
  21. :url => {:action => :category_text_field },
  22. :with => "'id='+ $F('"+id+"')")+"}") %>
  23.  
  24. ** from categories_controller **
  25. def category_text_field
  26. @cat = Category.find(params[:id])
  27. @all_categories = @cat.children
  28. render :update do |page|
  29. page.insert_html :bottom, 'box', render(:partial => "category_select", :locals => {:id => "category[selected_#{@cat.id}]"})
  30. end
  31. end
Add Comment
Please, Sign In to add comment