Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem 'mysql2'
#gem 'haml-rails'
gem 'haml'
gem 'simple_form'
gem 'friendly_id'
gem 'bcrypt-ruby', :require => 'bcrypt'
gem 'paperclip', :git => "git://github.com/thoughtbot/paperclip.git"

Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ GEM
factory_girl (~> 4.2.0)
railties (>= 3.0.0)
ffi (1.0.11)
friendly_id (4.0.8)
haml (3.1.4)
highline (1.6.11)
hike (1.2.1)
Expand Down Expand Up @@ -192,6 +193,7 @@ DEPENDENCIES
capybara-webkit
coffee-rails (~> 3.2.1)
factory_girl_rails
friendly_id
haml
jquery-rails
mysql2
Expand Down
15 changes: 15 additions & 0 deletions app/controllers/categories_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class CategoriesController < ApplicationController
before_filter :find_category, :only => [:show]
def index

end

def show

end

private
def find_category
@category = Category.find params[:id]
end
end
3 changes: 3 additions & 0 deletions app/models/category.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
class Category < ActiveRecord::Base
extend FriendlyId
attr_accessible :name, :exclusive
has_many :subcategories
has_many :products

validates :name, :presence => true

friendly_id :name, :use => :slugged
end
3 changes: 3 additions & 0 deletions app/models/subcategory.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
class Subcategory < ActiveRecord::Base
extend FriendlyId
belongs_to :category
has_many :products
attr_accessible :name, :category_id, :order

validates :name, :presence => true
validates_presence_of :category

friendly_id :name, :use => :slugged
end
1 change: 1 addition & 0 deletions app/views/categories/show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
%h1 Category!!
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
end
end

match ':category_name' => 'category#show', as: :category_show, via: :get
match ':category_name/:subcategory_name' => 'subcategories#show', as: :category_subcategory, via: :get

# See how all your routes lay out with "rake routes"

# This is a legacy wild controller route that's not recommended for RESTful applications.
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20130605055014_add_slugsto_category_subcategory.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class AddSlugstoCategorySubcategory < ActiveRecord::Migration
def change
# Change to Category table
add_column :categories, :slug, :string
add_index :categories, :slug, unique: true

#Change to Subcategory table
add_column :subcategories, :slug, :string
add_index :subcategories, :slug, unique: true
end
end
18 changes: 18 additions & 0 deletions db/migrate/20130605061330_create_friendly_id_slugs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class CreateFriendlyIdSlugs < ActiveRecord::Migration

def self.up
create_table :friendly_id_slugs do |t|
t.string :slug, :null => false
t.integer :sluggable_id, :null => false
t.string :sluggable_type, :limit => 40
t.datetime :created_at
end
add_index :friendly_id_slugs, :sluggable_id
add_index :friendly_id_slugs, [:slug, :sluggable_type], :unique => true
add_index :friendly_id_slugs, :sluggable_type
end

def self.down
drop_table :friendly_id_slugs
end
end
19 changes: 18 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,27 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20130603015906) do
ActiveRecord::Schema.define(:version => 20130605061330) do

create_table "categories", :force => true do |t|
t.string "name", :null => false
t.boolean "exclusive", :default => false, :null => false
t.string "slug"
end

add_index "categories", ["slug"], :name => "index_categories_on_slug", :unique => true

create_table "friendly_id_slugs", :force => true do |t|
t.string "slug", :null => false
t.integer "sluggable_id", :null => false
t.string "sluggable_type", :limit => 40
t.datetime "created_at"
end

add_index "friendly_id_slugs", ["slug", "sluggable_type"], :name => "index_friendly_id_slugs_on_slug_and_sluggable_type", :unique => true
add_index "friendly_id_slugs", ["sluggable_id"], :name => "index_friendly_id_slugs_on_sluggable_id"
add_index "friendly_id_slugs", ["sluggable_type"], :name => "index_friendly_id_slugs_on_sluggable_type"

create_table "products", :force => true do |t|
t.integer "code"
t.string "name"
Expand All @@ -37,8 +51,11 @@
t.string "name", :null => false
t.integer "category_id", :null => false
t.integer "order", :default => 1
t.string "slug"
end

add_index "subcategories", ["slug"], :name => "index_subcategories_on_slug", :unique => true

create_table "users", :force => true do |t|
t.string "first_name", :null => false
t.string "last_name", :null => false
Expand Down