Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/models/forum_category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ class ForumCategory < ApplicationRecord

validates :name, :slug, :color, presence: true

validates :slug, uniqueness: true
validates :name, uniqueness: true

def color
colour = super
colour.start_with?("#") ? colour : "##{colour}"
Expand Down
2 changes: 2 additions & 0 deletions app/models/forum_post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ class ForumPost < ApplicationRecord
belongs_to :forum_thread, counter_cache: true, touch: true
belongs_to :user

has_rich_text :body

validates :user_id, :body, presence: true

scope :sorted, -> { order(:created_at) }
Expand Down
8 changes: 4 additions & 4 deletions app/models/forum_thread.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ class ForumThread < ApplicationRecord

belongs_to :forum_category
belongs_to :user
has_many :forum_posts
has_many :forum_subscriptions
has_many :optin_subscribers, -> { where(forum_subscriptions: {subscription_type: :optin}) }, through: :forum_subscriptions, source: :user
has_many :optout_subscribers, -> { where(forum_subscriptions: {subscription_type: :optout}) }, through: :forum_subscriptions, source: :user
has_many :forum_posts, dependent: :destroy
has_many :forum_subscriptions, dependent: :destroy
has_many :optin_subscribers, -> { where(forum_subscriptions: {subscription_type: :optin}) }, through: :forum_subscriptions, source: :user, dependent: :destroy
has_many :optout_subscribers, -> { where(forum_subscriptions: {subscription_type: :optout}) }, through: :forum_subscriptions, source: :user, dependent: :destroy
has_many :users, through: :forum_posts

accepts_nested_attributes_for :forum_posts
Expand Down
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
get :mine
get :participating
get "category/:id", to: "forum_categories#index", as: :forum_category
get "categories/new", to: "forum_categories#new", as: :new_forum_category
get "categories/:id/edit", to: "forum_categories#edit", as: :edit_forum_category
post "categories", to: "forum_categories#create", as: :create_forum_category
delete "categories/:id", to: "forum_categories#destroy", as: :destroy_forum_category
patch "categories/:id", to: "forum_categories#update", as: :update_forum_category
end

resources :forum_posts, path: :posts do
Expand Down