Permalink
Browse files

Merge branch 'library' of github.com:elm-city-craftworks/practicing-r…

…uby-web into library
  • Loading branch information...
practicingruby committed Apr 8, 2012
2 parents ac0f179 + b7c3f90 commit 15dfc6574e52ed62aea1675831ea381b0508f525
@@ -7,9 +7,11 @@ class ArticlesController < ApplicationController
def index
if params["volume"]
- @volumes = Volume.where(:number => params["volume"].to_i)
+ @article_groupings = Volume.where(:number => params["volume"].to_i)
+ elsif params["collection"]
+ @article_groupings = Collection.where(:slug => params["collection"])
else
- @volumes = Volume.order("number desc")
+ @article_groupings = Volume.order("number desc")
end
end
View
@@ -1,6 +1,7 @@
class Article < ActiveRecord::Base
has_many :comments, :as => :commentable
belongs_to :volume
+ belongs_to :collection
validates_presence_of :issue_number
View
@@ -0,0 +1,3 @@
+class Collection < ActiveRecord::Base
+ has_many :articles
+end
View
@@ -1,3 +1,7 @@
class Volume < ActiveRecord::Base
has_many :articles
+
+ def name
+ "Volume #{number}"
+ end
end
@@ -10,6 +10,9 @@
%p
= f.label :volume_id
= f.collection_select :volume_id, Volume.order("number desc"), :id, :number
+%p
+ = f.label :collection_id
+ = f.collection_select :collection_id, Collection.all, :id, :name
%p
= f.label :issue_number
%br
@@ -3,18 +3,16 @@
= button_to "New article", new_admin_article_path, :method => :get
#article
- %p Practicing Ruby is currently in a break period, but I will resume publishing articles soon. The first article for volume 4 will be released on April 10, 2012.
+ - @article_groupings.each do |group|
- - @volumes.each do |volume|
-
- - if volume.articles.any?
- %h2= "Articles from Volume #{volume.number}"
- %p.left= volume.description
+ - if group.articles.any?
+ %h3= group.name
+ %p.left= group.description
%ul.index
- - volume.articles.published.each do |a|
+ -group.articles.published.each do |a|
%li= link_to a.full_subject, article_path(a)
- if current_user.admin?
- - volume.articles.drafts.each do |a|
+ - group.articles.drafts.each do |a|
%li= link_to "[DRAFT] #{a.full_subject}", article_path(a)
@@ -4,3 +4,10 @@
%p
= link_to "Volume #{v.number}", "/volume/#{v.number}"
= v.description
+
+%h2 By Collection
+
+- Collection.all.each do |c|
+ %p
+ = link_to c.name, "/collection/#{c.slug}"
+ = c.description
View
@@ -7,6 +7,7 @@
match "/library" => 'home#library'
match "/volume/:volume/" => 'articles#index'
match "/volume/:volume/issue/:issue" => 'articles#show'
+ match "/collection/:collection/" => 'articles#index'
resources :articles do
member do
@@ -0,0 +1,12 @@
+class CreateCollections < ActiveRecord::Migration
+ def change
+ create_table :collections do |t|
+ t.integer :id
+ t.string :name
+ t.text :description
+ t.string :image_file_name
+ t.string :slug
+ t.timestamps
+ end
+ end
+end
@@ -0,0 +1,7 @@
+class AddCollectionIdToArticles < ActiveRecord::Migration
+ def change
+ change_table :articles do |t|
+ t.belongs_to :collection
+ end
+ end
+end
View
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120406161709) do
+ActiveRecord::Schema.define(:version => 20120407205455) do
create_table "announcements", :force => true do |t|
t.text "title"
@@ -41,6 +41,7 @@
t.datetime "updated_at"
t.text "issue_number"
t.integer "volume_id"
+ t.integer "collection_id"
end
create_table "authorization_links", :force => true do |t|
@@ -59,6 +60,15 @@
t.datetime "updated_at"
end
+ create_table "collections", :force => true do |t|
+ t.string "name"
+ t.text "description"
+ t.string "image_file_name"
+ t.string "slug"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
create_table "comments", :force => true do |t|
t.integer "commentable_id"
t.string "commentable_type"

0 comments on commit 15dfc65

Please sign in to comment.