Skip to content

Commit

Permalink
Articles by author snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
nebirhos committed May 7, 2012
1 parent 2d7b03c commit e63c65f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 4 deletions.
6 changes: 6 additions & 0 deletions app/cells/content/articles_authors_list.html.erb
@@ -0,0 +1,6 @@
<h3>Authors</h3>
<ul>
<% @authors.each do |author| %>
<li><%= link_to "#{author.firstname} #{author.lastname} (#{author.articles.count})", "#{@url}?author=#{author.pretty_url}" %></li>
<% end %>
</ul>
1 change: 1 addition & 0 deletions app/cells/content/articles_categories_list.html.erb
@@ -1,3 +1,4 @@
<h3>Categories</h3>
<ul>
<% @categories.each do |category| %>
<li><%= link_to "#{category.name} (#{category.articles_count})", "#{@url}?category=#{category.pretty_url}" %></li>
Expand Down
21 changes: 19 additions & 2 deletions app/cells/content_cell.rb
Expand Up @@ -27,8 +27,19 @@ def articles_list(args)
@articles = @articles.where("categorizations.category_id IN (?)", args[:options][:categories]) if args[:options][:categories]
else
# show only current category
@meta_title = I18n.t 'public.articles.category', :name => Category.find_by_pretty_url( params[:category] ).name
@articles = @articles.joins(:categories).where( "categories.pretty_url = ?", params[:category] )
category = Category.find_by_pretty_url( params[:category] )
if category
@meta_title = I18n.t 'public.articles.category', :name => category.name
@articles = @articles.joins(:categories).where( "categories.pretty_url = ?", params[:category] )
end
end

unless params[:author].blank?
author = User.find_by_pretty_url( params[:author] )
if author
@meta_title = I18n.t 'public.articles.author', :name => "#{author.firstname} #{author.lastname}"
@articles = @articles.joins(:user).where( "users.pretty_url" => params[:author])
end
end

per_page = ( args[:options][:per_page].blank? )? 10 : args[:options][:per_page]
Expand All @@ -43,6 +54,12 @@ def articles_categories_list(args)
render
end

def articles_authors_list(args)
@authors = User.active_writers
@url = args[:options][:archive_url]
render
end

def twitter_stream(args)
render
end
Expand Down
5 changes: 5 additions & 0 deletions app/cells/content_cell.yml
Expand Up @@ -29,6 +29,11 @@ cell:
desc: List all the categories with published articles
serialized_attributes:
archive_url: string
- name: Articles Authors
method: articles_authors_list
desc: List all the users with published articles
serialized_attributes:
archive_url: string
- name: Twitter stream
method: twitter_stream
desc: Stream of tweets from a twitter account
Expand Down
6 changes: 4 additions & 2 deletions app/models/user.rb
Expand Up @@ -5,7 +5,7 @@ class User < ActiveRecord::Base

# Setup accessible (or protected) attributes for your model
attr_accessible :firstname, :lastname, :email, :password, :password_confirmation, :remember_me, :lang, :pretty_url

has_many :grades
has_many :roles, :through => :grades
accepts_nested_attributes_for :grades
Expand All @@ -19,11 +19,13 @@ class User < ActiveRecord::Base
validates :lastname, :presence => true
validates :password, :presence => true, :length => { :minimum => 8 }
validates :password_confirmation, :presence => true, :length => { :minimum => 8 }

scope :admins, includes(:grades, :roles).where("roles.name = ?", "admin")
scope :writers, includes(:grades, :roles).where("roles.name = ?", "article_writer")
scope :premiums, includes(:grades, :roles).where("roles.name = ?", "premium_user")

scope :active_writers, joins(:articles).select('DISTINCT users.*')

# = CSV export =
comma do
id
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Expand Up @@ -260,6 +260,7 @@ en:
article: Article
all_categories: "All categories"
category: "Articles in category %{name}"
author: "Articles by %{name}"
pages:
pages: Pages
page: Page
Expand Down
1 change: 1 addition & 0 deletions config/locales/it.yml
Expand Up @@ -253,6 +253,7 @@ it:
article: Articolo
all_categories: "Tutte le categorie"
category: "Articoli nella categoria %{name}"
author: "Articoli di %{name}"
pages:
pages: Pagine
page: Pagina
Expand Down

0 comments on commit e63c65f

Please sign in to comment.