Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
posts, topics, forums tests, controllers, models, views
- Loading branch information
Showing
49 changed files
with
16,060 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
require "bundler/gem_tasks" | ||
require 'bundler/gem_tasks' |
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 @@ | ||
// Place all the behaviors and hooks related to the matching controller here. | ||
// All this logic will automatically be available in application.js. |
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 @@ | ||
// Place all the behaviors and hooks related to the matching controller here. | ||
// All this logic will automatically be available in application.js. |
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 @@ | ||
// Place all the behaviors and hooks related to the matching controller here. | ||
// All this logic will automatically be available in application.js. |
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,4 @@ | ||
/* | ||
Place all the styles related to the matching controller here. | ||
They will automatically be included in application.css. | ||
*/ |
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,4 @@ | ||
/* | ||
Place all the styles related to the matching controller here. | ||
They will automatically be included in application.css. | ||
*/ |
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,4 @@ | ||
/* | ||
Place all the styles related to the matching controller here. | ||
They will automatically be included in application.css. | ||
*/ |
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,15 @@ | ||
require_dependency 'ruboard/application_controller' | ||
|
||
module Ruboard | ||
class ForumsController < Ruboard::ApplicationController | ||
|
||
def index | ||
@forums = Ruboard::Forum.with_topics | ||
end | ||
|
||
def show | ||
@forum = Ruboard::Forum.with_topics.find(params[:id]) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require_dependency "ruboard/application_controller" | ||
|
||
module Ruboard | ||
class PostsController < ApplicationController | ||
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,19 @@ | ||
require_dependency 'ruboard/application_controller' | ||
|
||
module Ruboard | ||
class TopicsController < Ruboard::ApplicationController | ||
|
||
before_filter :find_forum | ||
|
||
def show | ||
@topic = @forum.topics.find(params[:id]) | ||
@posts = @topic.posts.includes(:user) | ||
end | ||
|
||
private | ||
def find_forum | ||
@forum = Ruboard::Forum.find(params[:forum_id]) | ||
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 |
---|---|---|
@@ -1,8 +1,13 @@ | ||
module Ruboard | ||
class Post < ActiveRecord::Base | ||
attr_accessible :body, :user | ||
|
||
belongs_to :topic | ||
belongs_to :user | ||
attr_accessible :body, :user, :body | ||
|
||
belongs_to :topic, :counter_cache => true | ||
belongs_to :user, :class_name => Ruboard.user_class.to_s | ||
|
||
validates :body, :presence => true | ||
|
||
delegate :name, :to => :user, :prefix => true, :allow_nil => true | ||
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 |
---|---|---|
@@ -1,9 +1,40 @@ | ||
require 'friendly_id' | ||
|
||
module Ruboard | ||
class Topic < ActiveRecord::Base | ||
extend FriendlyId | ||
|
||
attr_accessible :title, :forum, :user | ||
|
||
has_many :posts, :dependent => :destroy | ||
belongs_to :user | ||
has_many :posts, :dependent => :destroy, :order => 'ruboard_posts.created_at DESC' | ||
has_many :views, :as => :viewable | ||
belongs_to :user, :class_name => Ruboard.user_class.to_s | ||
belongs_to :forum | ||
|
||
validates :title, :presence => true, :length => { :minimum => 3, :maximum => 250 } | ||
|
||
friendly_id :title, :use => :slugged | ||
|
||
accepts_nested_attributes_for :posts | ||
|
||
before_save :set_first_post_user | ||
|
||
def register_view_by(user) | ||
return unless user | ||
|
||
view = self.views.find_or_create_by_user_id(user.id) | ||
view.increment!(:count) | ||
self.increment!(:views_count) | ||
end | ||
|
||
def view_for(user) | ||
self.views.find_by_user_id(user.id) | ||
end | ||
|
||
private | ||
def set_first_post_user | ||
post = self.posts.first | ||
post.user = self.user | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Ruboard | ||
class View < ActiveRecord::Base | ||
attr_accessible :user, :count | ||
|
||
belongs_to :user, :class_name => Ruboard.user_class.to_s | ||
belongs_to :viewable, :polymorphic => true | ||
|
||
validates :viewable_id, :viewable_type, :presence => true | ||
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,3 @@ | ||
<div class="ruboardForums__forum" id="forum_<%= forum.id %>"> | ||
<%= render 'ruboard/topics/list', :forum => forum %> | ||
</div> |
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,3 @@ | ||
<div class="ruboardForums"> | ||
<%= render @forums %> | ||
</div> |
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,3 @@ | ||
<div class="ruboardForums"> | ||
<%= render @forum %> | ||
</div> |
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,10 @@ | ||
<table class="ruboardTopics__posts table table-bordered"> | ||
<thead> | ||
<tr> | ||
<th colspan="2" class="ruboardTopics__posts__title"><%= link_to topic.title, ruboard.forum_topic_path(forum, topic) %></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<%= render posts, :forum => forum, :topic => topic %> | ||
</tbody> | ||
</table> |
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,30 @@ | ||
<tr> | ||
<td><%= post.user_name %></td> | ||
<td> | ||
<div class="ruboardTopics__posts__info" id="post-<%= post.id %>"> | ||
<div class="ruboardTopics__posts__info__created"> | ||
<%= "#{t('activerecord.attributes.post.created_at')}: #{l(post.created_at, :format => :ruboard_full)}" %> | ||
</div> | ||
<div class="ruboardTopics__posts__info__number"> | ||
<%= link_to "##{post_counter + 1}", "#post-#{post.id}" %> | ||
</div> | ||
</div> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td rowspan="3" class="ruboardTopics__posts__user"> | ||
Avatar | ||
<p><%= t('ruboard.user.posts') %>: 0</p> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td colspan="2"> | ||
<div class="ruboardTopics__posts__body"> | ||
<%= post.body %> | ||
</div> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td>Forum Sign</td> | ||
<td>Menu</td> | ||
</tr> |
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,13 @@ | ||
<table class="ruboardForums__topics table table-bordered"> | ||
<thead> | ||
<tr> | ||
<th colspan="2"><%= link_to forum.title, ruboard.forum_path(forum) %></th> | ||
<th><%= t('activerecord.attributes.topic.answers') %></th> | ||
<th><%= t('activerecord.attributes.topic.views') %></th> | ||
<th><%= t('activerecord.attributes.topic.updates') %></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<%= render forum.topics, :forum => forum %> | ||
</tbody> | ||
</table> |
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,9 @@ | ||
<tr> | ||
<td>Status</td> | ||
<td> | ||
<%= link_to topic.title, ruboard.forum_topic_path(forum, topic) %> | ||
</td> | ||
<td><%= topic.posts.size %></td> | ||
<td><%= topic.views_count %></td> | ||
<td><%= l(topic.updated_at, :format => :ruboard_full) %></td> | ||
</tr> |
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,3 @@ | ||
<div class="ruboardTopics"> | ||
<%= render 'ruboard/posts/list', :topic => @topic, :forum => @forum, :posts => @posts %> | ||
</div> |
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,12 @@ | ||
en: | ||
activerecord: | ||
models: | ||
topic: | ||
one: 'Topic' | ||
other: 'Topics' | ||
attributes: | ||
topic: | ||
title: 'Subject' | ||
answers: 'Answers' | ||
views: 'Views' | ||
updates: 'Updates' |
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,20 @@ | ||
ru: | ||
activerecord: | ||
models: | ||
topic: | ||
one: 'Тема' | ||
few: 'Темы' | ||
many: 'Тем' | ||
other: 'Темы' | ||
attributes: | ||
topic: | ||
title: 'Название' | ||
answers: 'Ответов' | ||
views: 'Просмотров' | ||
updates: 'Обновления' | ||
post: | ||
body: 'Сообщение' | ||
created_at: 'Отправлено' | ||
time: | ||
formats: | ||
ruboard_full: '%d %B %Y %H:%M' |
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 |
---|---|---|
@@ -1,2 +1,7 @@ | ||
Ruboard::Engine.routes.draw do | ||
root :to => 'forums#index' | ||
|
||
resources :forums, :only => [ :index, :show ] do | ||
resources :topics, :only => [ :show ] | ||
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 |
---|---|---|
@@ -1,15 +1,18 @@ | ||
class CreateRuboardTopics < ActiveRecord::Migration | ||
def change | ||
create_table :ruboard_topics do |t| | ||
t.string :title, :null => false | ||
t.integer :forum_id, :null => false | ||
t.integer :user_id, :null => false | ||
t.boolean :closed, :null => false, :default => false | ||
t.boolean :pinned, :null => false, :default => false | ||
t.string :slug | ||
|
||
t.timestamps | ||
end | ||
|
||
add_index :ruboard_topics, :forum_id | ||
add_index :ruboard_topics, :user_id | ||
add_index :ruboard_topics, :slug, :unique => true | ||
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,24 @@ | ||
class CreateRuboardViews < ActiveRecord::Migration | ||
def self.up | ||
|
||
add_column :ruboard_topics, :views_count, :integer, :default => 0 | ||
|
||
create_table :ruboard_views do |t| | ||
t.integer :user_id | ||
t.integer :viewable_id | ||
t.string :viewable_type | ||
t.datetime :current_viewed_at | ||
t.datetime :past_viewed_at | ||
t.integer :count, :default => 0 | ||
t.timestamps | ||
end | ||
|
||
add_index :ruboard_views, [:viewable_id, :viewable_type], :name => 'ruboard_views_viewable_idx' | ||
add_index :ruboard_views, :user_id | ||
end | ||
|
||
def self.down | ||
remove_column :ruboard_topics, :views_count | ||
drop_table :ruboard_views | ||
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,14 @@ | ||
class AddCacheCounterToTopics < ActiveRecord::Migration | ||
def self.up | ||
add_column :ruboard_topics, :posts_count, :integer, :default => 0 | ||
|
||
Ruboard::Topic.reset_column_information | ||
Ruboard::Topic.find_each do |t| | ||
Ruboard::Topic.update_counters t.id, :posts_count => t.posts.length | ||
end | ||
end | ||
|
||
def self.down | ||
remove_column :ruboard_topics, :posts_count | ||
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 |
---|---|---|
@@ -1,6 +1,16 @@ | ||
require "ruboard/version" | ||
require 'ruboard/version' | ||
require 'ruboard/engine' | ||
|
||
module Ruboard | ||
# Your code goes here... | ||
mattr_accessor :user_class | ||
|
||
class << self | ||
def user_class | ||
begin | ||
Object.const_get(@@user_class) | ||
rescue NameError | ||
@@user_class.constantize | ||
end | ||
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
Oops, something went wrong.