-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
266 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
class CategoryController < ApplicationController | ||
load_and_authorize_resource | ||
|
||
layout :article_layout, :only => [:list] | ||
|
||
def index | ||
end | ||
|
||
def show | ||
end | ||
|
||
def create | ||
end | ||
|
||
def update | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def destroy | ||
end | ||
|
||
def list | ||
@layout = params[:name] | ||
end | ||
|
||
private | ||
def article_layout | ||
@layout | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module CategoryHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class Category < ActiveRecord::Base | ||
|
||
has_ancestry | ||
has_many :articles | ||
|
||
validates :name, :presence => true, :uniqueness => true | ||
validates :layout, :presence => true | ||
validates :description, :presence => true | ||
validates :url, :presence => true, :uniqueness => true | ||
|
||
before_create :layout_exists | ||
|
||
validates_format_of :url, :with => /\A[a-zA-Z0-9]+\z/, :message => "No special characters are allowed" | ||
validates_length_of :url, :in => 3..10, :too_short => "Must have atleast 3 characters", :too_long => "Must have 10 or fewers characters" | ||
|
||
private | ||
def layout_exists | ||
if !File.exists?(Rails.root.join("app", "views", "layouts", "#{self.layout}.html.erb")) | ||
File.open(Rails.root.join("app", "views", "layouts", "#{self.layout}.html.erb"), 'w') {|f| f.write("<html>\n<body>\n</body>\n</html>\n") } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Category#create</h1> | ||
<p>Find me in app/views/category/create.html.erb</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Category#destroy</h1> | ||
<p>Find me in app/views/category/destroy.html.erb</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Category#edit</h1> | ||
<p>Find me in app/views/category/edit.html.erb</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Category#index</h1> | ||
<p>Find me in app/views/category/index.html.erb</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Category#list</h1> | ||
<p>Find me in app/views/category/list.html.erb</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Category#show</h1> | ||
<p>Find me in app/views/category/show.html.erb</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Category#update</h1> | ||
<p>Find me in app/views/category/update.html.erb</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class CreateCategoriesAndMore < ActiveRecord::Migration | ||
def self.up | ||
create_table :categories do |t| | ||
t.string :name | ||
t.string :layout | ||
t.string :description | ||
t.string :url | ||
t.string :ancestry | ||
t.timestamps | ||
end | ||
|
||
add_index :categories, :ancestry | ||
add_column :articles, :category_id, :integer | ||
|
||
# rename normal role | ||
r = Role.find(2) | ||
r.name = "Editor" | ||
r.save | ||
# add new, regular person role | ||
r = Role.new(:name => "Regular") | ||
r.id = 3 | ||
r.save | ||
end | ||
|
||
def self.down | ||
drop_table :categories | ||
|
||
remove_index :categories, :ancestry | ||
remove_column :articles, :category_id | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,7 @@ | |
@user.save | ||
end | ||
|
||
Given /^I am an editor$/ do | ||
@user.roles = [Role.find_by_name("Editor")] | ||
@user.save | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.