Skip to content

Commit

Permalink
Add slugs and a list of unpublished drafts
Browse files Browse the repository at this point in the history
  • Loading branch information
thutterer committed Jun 5, 2020
1 parent c013dab commit c712fc7
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Rails engine for blogging using Trix and MongoDB.
Add this line to your application's `Gemfile`:

```ruby
gem 'bongo'
gem "bongo"
```

And then execute:
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/bongo/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ArticlesController < ApplicationController
before_action :set_article, only: [:show, :edit, :update, :destroy]

def index
@articles = policy_scope(Article).order(publish_at: :desc)
@articles = policy_scope(Article).published.order(publish_at: :desc)
respond_to do |format|
format.html
format.rss do
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/bongo/drafts_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Bongo
class DraftsController < ArticlesController
def index
@drafts = policy_scope(Article).not.published.order(updated_at: :desc)
end
end
end
4 changes: 4 additions & 0 deletions app/models/bongo/article.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module Bongo
class Article
include Mongoid::Document
include Mongoid::Timestamps::Updated
include Mongoid::Slug

slug :title, history: true

field :title, type: String
field :text, type: String
Expand Down
5 changes: 2 additions & 3 deletions app/views/bongo/articles/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<header>
<% if policy(Bongo::Article).create? %>
<%= link_to new_article_path do %>
<b>New Article</b>
<%= link_to drafts_url do %>
<i>Drafts</i>
<% end %>
<hr>
<% end %>
</header>

Expand Down
16 changes: 16 additions & 0 deletions app/views/bongo/drafts/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<header>
<% if policy(Bongo::Article).create? %>
<%= link_to new_article_path do %>
<b>New Article</b>
<% end %>
<% end %>
</header>

<ul>
<% @drafts.each do |draft| %>
<li>
<%= link_to draft.title, draft %><br>
<small>last modified <%= distance_of_time_in_words_to_now(draft.updated_at) %> ago</small>
</li>
<% end %>
</ul>
1 change: 1 addition & 0 deletions bongo.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Gem::Specification.new do |spec|

spec.add_runtime_dependency "rails", "~> 6.0.3"
spec.add_runtime_dependency "mongoid", "~> 7.0.5"
spec.add_runtime_dependency "mongoid-slug", ">= 6"
spec.add_runtime_dependency "aws-sdk-s3", "~> 1"
spec.add_runtime_dependency "pundit", "~> 2.1"
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Bongo::Engine.routes.draw do
root to: "articles#index"
resources :articles
resources :drafts
resources :files, only: :create
end
1 change: 1 addition & 0 deletions lib/bongo.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require "mongoid_slug"
require "bongo/engine"

module Bongo
Expand Down
2 changes: 1 addition & 1 deletion lib/bongo/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Bongo
VERSION = '0.1.1'
VERSION = "0.2.0"
end

0 comments on commit c712fc7

Please sign in to comment.