Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 14 commits
  • 17 files changed
  • 0 commit comments
  • 2 contributors
View
13 app/controllers/articles_controller.rb
@@ -7,14 +7,17 @@ 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")
+ redirect_to "/library"
end
end
def show
authenticate_admin if @article.status == "draft"
+
@comments = @article.comments.order("created_at")
end
@@ -45,7 +48,11 @@ def shared
private
def find_article
- @article = Article.find(params[:id])
+ if params[:volume] && params[:issue]
+ @article = Article.find_by_issue_number("#{params[:volume]}.#{params[:issue]}")
+ else
+ @article = Article.find(params[:id])
+ end
end
def authenticate_admin
View
9 app/controllers/home_controller.rb
@@ -2,14 +2,13 @@ class HomeController < ApplicationController
skip_before_filter :authenticate
skip_before_filter :authenticate_user
- layout "landing"
-
def index
if current_user
- redirect_to articles_path
+ return redirect_to articles_path
end
- @recent_topics = Article.published.order("created_at DESC").limit(5)
- end
+ @recent_topics = Article.published.order("published_time DESC").limit(5)
+ render :index, :layout => "landing"
+ end
end
View
3  app/models/article.rb
@@ -1,11 +1,10 @@
class Article < ActiveRecord::Base
has_many :comments, :as => :commentable
belongs_to :volume
+ belongs_to :collection
validates_presence_of :issue_number
- default_scope { order(:created_at) }
-
def self.in_volume(number)
includes(:volume)
.where("volumes.number = ?", number)
View
3  app/models/collection.rb
@@ -0,0 +1,3 @@
+class Collection < ActiveRecord::Base
+ has_many :articles
+end
View
4 app/models/volume.rb
@@ -1,3 +1,7 @@
class Volume < ActiveRecord::Base
has_many :articles
+
+ def name
+ "Volume #{number}"
+ end
end
View
3  app/views/admin/articles/_form.html.haml
@@ -11,6 +11,9 @@
= 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
= f.text_field :issue_number
View
14 app/views/articles/index.haml
@@ -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.order("published_time").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)
View
23 app/views/home/library.html.haml
@@ -0,0 +1,23 @@
+%p
+ %em
+ As a subscriber to Practicing Ruby, you get full access to my library of back issues. The archives currently contain a total of
+ = Article.where(:status => "published").count
+ issues spread across
+ = Volume.count
+ volumes, and several new articles get added each month.
+
+%p Back issues are organized in two ways: by thematic collections and by chronologically-ordered volumes. Follow your interests and feel free to jump around the collections and volumes. The way you read this content is entirely up to you and your studies should happen on your own schedule, not mine!
+
+%h3 By Collection
+
+- Collection.all.each do |c|
+ %p
+ = link_to c.name, "/collection/#{c.slug}"
+ = c.description
+
+%h3 By Volume
+
+- Volume.all.each do |v|
+ %p
+ = link_to "Volume #{v.number}", "/volume/#{v.number}"
+ = v.description
View
3  app/views/layouts/application.html.haml
@@ -23,7 +23,6 @@
lovingly curated by Gregory Brown
%h1#header= link_to "Practicing Ruby", home_path
-
- = render :partial => "shared/navigation"
+ %hr
= render :partial => "shared/broadcasts"
= yield
View
6 app/views/shared/_navigation.html.haml
@@ -1,10 +1,10 @@
- if current_user
#navigation
%strong FREE:
- = link_to "Volume 1", articles_path(:volume => 1)
- = link_to "Volume 2", articles_path(:volume => 2)
+ = link_to "Volume 1", "/volume/1"
+ = link_to "Volume 2", "/volume/2"
%strong MEMBERS:
- = link_to "Volume 3", articles_path(:volume => 3)
+ = link_to "Volume 3", "/volume/3"
.right
%strong SPECIAL:
Coming Soon!
View
1  app/views/shared/_upper_navigation.html.haml
@@ -1,6 +1,7 @@
- if current_user
#upper_navigation
.right
+ = link_to "Library", "/library"
= link_to "FAQ", "/community/faq"
= link_to "Updates", announcements_path
= link_to "Settings", edit_user_path(current_user), :class => "user_pages"
View
5 config/routes.rb
@@ -4,6 +4,11 @@
match "/hooks/#{MailChimp::SETTINGS[:webhook_key]}" => 'hooks#receive'
match '/articles/shared/:secret' => 'articles#shared', :as => "shared_article"
+ 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
get 'share'
View
12 db/migrate/20120407204814_create_collections.rb
@@ -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
View
7 db/migrate/20120407205455_add_collection_id_to_articles.rb
@@ -0,0 +1,7 @@
+class AddCollectionIdToArticles < ActiveRecord::Migration
+ def change
+ change_table :articles do |t|
+ t.belongs_to :collection
+ end
+ end
+end
View
12 db/schema.rb
@@ -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"
View
2  test/integration/account_linking_test.rb
@@ -159,6 +159,6 @@ def assert_email_manually_entered(email)
def assert_activated
visit "/sessions/link/#{@auth_link.secret}"
- assert_equal articles_path, current_path
+ assert_equal library_path, current_path
end
end
View
6 test/integration/disabled_accounts_test.rb
@@ -9,9 +9,9 @@ class DisabledAccountsTest < ActionDispatch::IntegrationTest
test "can log in normally when account is not disabled" do
sign_user_in
- visit articles_path
+ visit library_path
- assert_equal articles_path, current_path
+ assert_equal library_path, current_path
end
test "gets rerouted to session problem page when account is disabled" do
@@ -21,4 +21,4 @@ class DisabledAccountsTest < ActionDispatch::IntegrationTest
assert_equal problems_sessions_path, current_path
end
-end
+end

No commit comments for this range

Something went wrong with that request. Please try again.