Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 0.44 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. I want to create a method that will be available in all controllers, and views
  2. def categories
  3.   @categories = Category.all
  4. end
  5.        
  6. def list
  7.   categories
  8.   @products = Product.order('title').page(params[:page]).per(4)
  9. end
  10.        
  11. helper_method :my_method
  12.        
  13. module ApplicationHelper
  14.   def get_all_categories
  15.      @categories = Category.all
  16.   end
  17. end
  18.        
  19. <% Category.all.each do |category| %>
  20.      <% do stuff to display all categories %>
  21. <% end %>