Skip to content

Instantly share code, notes, and snippets.

@posts = Post.search_by_title(search_param).default_order
@posts = @posts.select do |post|
(post.author == selected_author || any_author?) && (post.published? || current_admin)
end
@posts = Post.all
@posts = @posts.where(published: true) unless current_admin
@posts = @posts.where(author: selected_author) unless any_author?
@posts = @posts.search_by_title(search_param).default_order
@abaldwin88
abaldwin88 / first_or_create_callback.rb
Last active March 15, 2019 16:33
Scoping within first_or_create callback
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Activate the gem you are reporting the issue against.
-- DO NOT RUN IN PRODUCTION
-- Supported on PSQL 9.6+.
-- Note: If all your tables aren’t located in the public schema
-- be sure to modify the specified schemaname
do $$
declare
selectrow record;
begin
for selectrow in
select
class ApplicationRecord < ActiveRecord::Base
...
after_create_commit do
ActiveRecord::Base.connection.execute("CLUSTER #{self.class.table_name}")
end
end