class Object
Public Class Methods
regional(selected_region = nil, excluded_region = nil)
click to toggle source
@param [Region] selected_region @param [Region] excluded_region
# File lib/comunit/base/decorators/models/post_decorator.rb, line 14 def self.regional(selected_region = nil, excluded_region = nil) excluded_ids = Array(excluded_region&.subbranch_ids) if selected_region.nil? excluded_ids.any? ? where('region_id not in (?)', excluded_ids) : where('region_id is not null') else where(region_id: selected_region.subbranch_ids - excluded_ids) end end
Public Instance Methods
answer()
click to toggle source
post /polls/:id/results
# File lib/comunit/base/decorators/controllers/polls_controller_decorator.rb, line 16 def answer @entity.process_answers(current_user, params.require(:answer), owner_for_entity(true), visitor_slug) PollVote.where(poll_answer_id: @entity.answer_ids).each do |vote| NetworkEntitySyncJob.perform_later(vote.class.to_s, vote.id) end redirect_to results_poll_path(id: @entity.id) end
create()
click to toggle source
post /my/posts
# File lib/comunit/base/decorators/controllers/my/posts_controller_decorator.rb, line 5 def create @entity = Post.new(creation_parameters) if component_handler.allow_post_type?(@entity.post_type) && @entity.save apply_post_tags apply_post_categories NetworkPostSyncJob.perform_later(@entity.id, false) form_processed_ok(@entity.url) else form_processed_with_error(:new) end end
follows?(user)
click to toggle source
@param [User] user
# File lib/comunit/base/decorators/models/user_decorator.rb, line 23 def follows?(user) UserLink.where(follower: self, followee: user).exists? end
full_name(include_patronymic = false)
click to toggle source
@param [TrueClass|FalseClass] include_patronymic
# File lib/comunit/base/decorators/models/user_decorator.rb, line 16 def full_name(include_patronymic = false) result = [data.dig('profile', 'surname').to_s.strip, data.dig('profile', 'name')] result << data.dig('profile', 'patronymic').to_s.strip if include_patronymic result.compact.join(' ') end
legacy_show()
click to toggle source
# File lib/comunit/base/decorators/controllers/posts_controller_decorator.rb, line 34 def legacy_show @entity = Post.list_for_visitors.find_by(slug: params[:slug]) if @entity.nil? handle_http_404("Cannot find non-deleted post #{params[:id]}") else @entity.increment :view_count @entity.increment :rating, 0.0025 @entity.save render :show end end
prepare_slug()
click to toggle source
# File lib/comunit/base/decorators/models/post_decorator.rb, line 23 def prepare_slug postfix = (created_at || Time.now).strftime('%d%m%Y') if slug.blank? self.slug = "#{Canonizer.transliterate(title.to_s)}_#{postfix}" end slug_limit = 200 + postfix.length + 1 self.slug = slug.downcase[0..slug_limit] end
profile_name()
click to toggle source
# File lib/comunit/base/decorators/models/user_decorator.rb, line 10 def profile_name result = full_name result.blank? ? screen_name : full_name end
redirect_after_creation()
click to toggle source
# File lib/comunit/base/decorators/controllers/my/profiles_controller_decorator.rb, line 16 def redirect_after_creation NetworkEntitySyncJob.perform_later(@entity.class.to_s, @entity.id) return_path = cookies['return_path'].to_s return_path = my_profile_path unless return_path[0] == '/' cookies.delete 'return_path', domain: :all form_processed_ok(return_path) end
regions()
click to toggle source
get /admin/posts/regions
# File lib/comunit/base/decorators/controllers/admin/posts_controller_decorator.rb, line 5 def regions @collection = RegionManager.new(current_user).for_tree(params[:parent_id]) end
site()
click to toggle source
# File lib/comunit/base/decorators/models/user_decorator.rb, line 27 def site Site.find_by(uuid: data.dig('comunit', 'site_id')) end
track_region_change()
click to toggle source
# File lib/comunit/base/decorators/models/post_decorator.rb, line 34 def track_region_change return unless region_id_changed? Region.update_post_count(*region_id_change) end
update()
click to toggle source
patch /my/posts/:id
# File lib/comunit/base/decorators/controllers/my/posts_controller_decorator.rb, line 18 def update if @entity.update(entity_parameters) apply_post_tags apply_post_categories NetworkPostSyncJob.perform_later(@entity.id, true) form_processed_ok(@entity.url) else form_processed_with_error(:edit) end end