# == Schema Information # # Table name: main_posts # # body :text # cached_votes_down :integer default(0) # cached_votes_score :integer default(0) # cached_votes_total :integer default(0) # cached_votes_up :integer default(0) # cached_weighted_average :float default(0.0) # cached_weighted_score :integer default(0) # cached_weighted_total :integer default(0) # comments_count :integer default(0) # invisible :boolean # slug :string # title :string # author_id :bigint # main_community_id :bigint not null # class Main::Post < ApplicationRecord belongs_to :author, class_name: "User", optional: true belongs_to :main_community, class_name: "Main::Community" has_many_attached :images has_many :comments, class_name: "Main::Comment", as: :commentable, dependent: :destroy acts_as_votable validates :title, presence: true extend FriendlyId friendly_id :title, use: :sequentially_slugged # Transliteration require "babosa" def normalize_friendly_id(string) string.to_slug.transliterate.normalize.downcase.to_s end end