Liroy Leshed Liroy Leshed - 3 months ago 9
SQL Question

Order by alphabetically in rails/SQL

Here's my categories view

- @categories.each do |category|
= link_to (category.name), category


And the controller..

class CategoriesController < ApplicationController

def index
@categories = Category.all
end

def show
end


private

def find_category
@category = Category.find(params[:id])
end
end


How do I order my categories' names alphabetically?

Thanks!

Answer

You can order:

@categories = Category.order(:name)
Comments