Stephen Sizer

Joined

3,780 Experience
16 Lessons Completed
1 Question Solved

Activity

Getting this error on the Run borales/actions-yarn@v2.0.0 step

yarn install v1.17.3
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@2.3.2: The platform "linux" is incompatible with this module.
info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@1.2.13: The platform "linux" is incompatible with this module.
info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.
error webpack-dev-server@4.5.0: The engine "node" is incompatible with this module. Expected version ">= 12.13.0". Got "10.16.3"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

Any ideas?

Posted in How to use Action Mailbox in Rails 6 Discussion

Here is a tough one. How do you stop the out of office replies coming through on these reply emails or is that something that is the downside of having the ability to reply to post via email?

Posted in Slow API Call any help?

I call the api for some lifestyle nutrition objects using the bellow and it returns 700 objects. Its currently taking 25-30secs. The lifestyle items do not have any attachments so don't understand why the call takes so long.

removing the attachments from the jbuilder file returns the API call in 8-12 secs. Am I missing something?

I have the following models:

# == Schema Information
#
# Table name: lifestyle_nutritions
#
#  id                :bigint           not null, primary key
#  due_date          :datetime
#  last_activity     :datetime
#  created_at        :datetime         not null
#  updated_at        :datetime         not null
#  client_id         :bigint           not null
#  lifestyle_plan_id :bigint
#
# Indexes
#
#  index_lifestyle_nutritions_on_client_id          (client_id)
#  index_lifestyle_nutritions_on_lifestyle_plan_id  (lifestyle_plan_id)
#
# Foreign Keys
#
#  fk_rails_...  (client_id => clients.id)
#  fk_rails_...  (lifestyle_plan_id => lifestyle_plans.id)
#
class LifestyleNutrition < ApplicationRecord
  belongs_to :client
  belongs_to :lifestyle_plan, optional: true
  has_many :lifestyle_nutrition_items, dependent: :destroy
  accepts_nested_attributes_for :lifestyle_nutrition_items, allow_destroy: true
  has_many :lifestyle_comments, dependent: :destroy

  scope :lifestyle_nutrition_between, ->(range) { where(due_date: range )}
  scope :not_overdue_lifestyle_nutrition, ->(timezone) { where('due_date >= ?', timezone ? Time.now.in_time_zone(timezone).to_date : Date.today) }
  scope :future_lifestyle_nutrition, ->(timezone) { not_overdue_lifestyle_nutrition(timezone) }
  scope :future_lifestyle_nutrition_between, ->(range, timezone) { lifestyle_nutrition_between(range).future_lifestyle_nutrition(timezone) }
  scope :overdue_lifestyle_nutrition, ->(timezone) { where('due_date < ?', timezone ? Time.now.in_time_zone(timezone).to_date : Date.today) }
  scope :past_lifestyle_nutrition, ->(timezone) { overdue_lifestyle_nutrition(timezone) }
  scope :past_lifestyle_nutrition_between, ->(range, timezone) { lifestyle_nutrition_between(range).past_lifestyle_nutrition(timezone) } 
  scope :nutritions_between, ->(range) { where(due_date: range )}

  def complete?
    lifestyle_nutrition_items.count === lifestyle_nutrition_items.actioned.count
  end

  def state
    if client
      timezone = client.user.timezone
      status = complete? ? "complete" : "pending"
      if due_date
        if status === "complete"
          "complete"
        elsif status === "pending" && due_date < (timezone ? Time.now.in_time_zone(timezone).to_date : Date.today)
          "missed"
        else
          "pending"
        end
      else
        "pending"
      end
    end
  end
end
# == Schema Information
#
# Table name: lifestyle_nutrition_items
#
#  id                        :bigint           not null, primary key
#  completed                 :boolean
#  notes                     :text
#  notification_sent         :boolean          default(FALSE)
#  notification_time         :datetime
#  notification_time_string  :string
#  prescription_description  :text
#  created_at                :datetime         not null
#  updated_at                :datetime         not null
#  lifestyle_nutrition_id    :bigint           not null
#  lifestyle_prescription_id :bigint           not null
#  lifestyle_type_id         :bigint           not null
#
# Indexes
#
#  index_lifestyle_nutrition_items_on_lifestyle_nutrition_id     (lifestyle_nutrition_id)
#  index_lifestyle_nutrition_items_on_lifestyle_prescription_id  (lifestyle_prescription_id)
#  index_lifestyle_nutrition_items_on_lifestyle_type_id          (lifestyle_type_id)
#
# Foreign Keys
#
#  fk_rails_...  (lifestyle_nutrition_id => lifestyle_nutritions.id)
#  fk_rails_...  (lifestyle_prescription_id => lifestyle_prescriptions.id)
#  fk_rails_...  (lifestyle_type_id => lifestyle_types.id)
#
class LifestyleNutritionItem < ApplicationRecord
  belongs_to :lifestyle_nutrition
  belongs_to :lifestyle_type
  belongs_to :lifestyle_prescription
  has_many :attachments, as: :attachable, dependent: :destroy

  scope :completed, -> { where(completed: true) }
  scope :actioned, -> { where.not(completed: nil) }

  before_destroy :destroy_notifications 
  before_save :set_notification_time


  def destroy_notifications
    self.lifestyle_nutrition.client.coach.notifications.where(type: "LifestyleNotification").each do |n|
      if (n.params[:lifestyle_nutrition_item][:id] == self.id) 
        n.destroy
      end
    end
  end

  def set_notification_time
    if notification_time_string.present?
      date = lifestyle_nutrition.due_date
      self.notification_time = get_notification_time(date, notification_time_string)
    end
  end

  def get_notification_time(date, time)
    notification_send_time = date
    hours = time.split(":")[0].to_i
    mins = time.split(":")[1].to_i
    notification_send_time = notification_send_time.advance(hours: hours)
    if mins > 0
      notification_send_time = notification_send_time.advance(minutes: mins)
    end

    if lifestyle_nutrition.client.user.timezone.present?
      notification_send_time = notification_send_time.in_time_zone(lifestyle_nutrition.client.user.timezone)
    else 
      notification_send_time = notification_send_time.in_time_zone("London")
    end
    notification_send_time -= notification_send_time.utc_offset
    notification_send_time = notification_send_time.utc
  end
end
# == Schema Information
#
# Table name: attachments
#
#  id              :bigint           not null, primary key
#  attachable_type :string
#  attachment_url  :string
#  cleaned_up      :boolean          default(FALSE)
#  converted       :boolean          default(FALSE)
#  copied          :boolean          default(FALSE)
#  file_type       :string
#  name            :string
#  original_url    :string
#  size            :integer
#  created_at      :datetime         not null
#  updated_at      :datetime         not null
#  attachable_id   :integer
#
class Attachment < ApplicationRecord
    before_create :set_original_url
    after_create :uploadcare
    belongs_to :attachable, polymorphic: true

    def isVideo?
      vid = file_type.split("/")[0]
      vid === "video"
    end

    def mp4?
      mp4 = file_type.split("/")[1]
      mp4 === "mp4"
    end

    def needsConverting?
      isVideo?
    end

    private 

    def set_original_url
      self.original_url = attachment_url
    end

    def uploadcare
      UploadcareJob.set(wait: 1.minute).perform_later(id)
    end
end

Jbuilder file.

json.lifestyle_nutritions @lifestyle_nutritions.each do |lifestyle|
    json.id lifestyle.id 
    json.due_date lifestyle.due_date.strftime('%Y/%m/%d')
    json.lifestyle_plan_id lifestyle.lifestyle_plan_id
    json.lifestyle_nutrition_items_attributes lifestyle.lifestyle_nutrition_items.order(:created_at).each do |item|
        json.id item.id
        json.lifestyle_type item.lifestyle_type.name 
        json.lifestyle_type_id item.lifestyle_type_id 
        json.lifestyle_prescription item.lifestyle_prescription.name 
        json.lifestyle_prescription_id item.lifestyle_prescription_id
        json.notification_time item.notification_time
        json.notification_time_string item.notification_time_string
        json.prescription_description item.prescription_description
        json.notes item.notes
        json.completed item.completed

        json.attachments item.attachments do |attachment|
            json.id attachment.id
            json.attachment_url attachment.attachment_url
            json.file_type attachment.file_type
        end
    end
    json.comments lifestyle.lifestyle_comments.order(:created_at).each do |comment|
        json.id comment.id
        json.lifestyle_nutrition_id comment.lifestyle_nutrition_id
        json.body comment.body 
        json.created_at comment.created_at
        json.commentable_type comment.commentable_type
        json.commenter_name comment.commentable_type == "Client" ? comment.commentable.name : comment.commentable.user.name
        json.commenter_initials comment.commentable && comment.commentable.name ? comment.commentable.name.initials : ""
        json.avatar_url comment.commentable && comment.commentable.user.avatar ? comment.commentable.user.avatar.url : nil
        json.attachments comment.attachments do |attachment|
            json.id attachment.id
            json.attachment_url attachment.attachment_url
            json.file_type attachment.file_type
        end
    end
end

Posted in This website is under heavy load (queue full)

Also thanks for the quick response Chris it's always appreciated :)

Posted in This website is under heavy load (queue full)

What's the best way to test slow queries?

Posted in This website is under heavy load (queue full)

I just got this message today on my production site. Website is running an ROR backend with a React front end.

Current site is running on Hatchbox/Digital Ocean with 16vCPUs, 32gb Memory and 200gb SSD so its a big server.

Looking at the graphs on DO

  • CPU doesn't go over 30%,
  • Memory is at 15%
  • The only thing that spiked was the Disk I/O that spiked to 1.17 mb/s

Any help would be appreciated.

Posted in Webpack and Purge CSS

Hi All,

I am trying to purge my css as I am using tailwind as outlined in the video Chris did. I'm getting an error.

postcss.config.js
let environment = {
plugins: [
require('tailwindcss'),
require('autoprefixer'),
require('postcss-import'),
require('postcss-flexbugs-fixes'),
require('postcss-preset-env')({
autoprefixer: {
flexbox: 'no-2009'
},
stage: 3
}),
require('@fullhuman/postcss-purgecss')({
content: [
'./app//*.html.erb',
'./app/helpers/
/.rb',
'./app/javascript/
/.js',
'./app/javascript//*.vue',
'./app/javascript/
/*.jsx',
],
defaultExtractor: content => content.match(/[A-Za-z0-9-_:/]+/g) || []
})
]
}

module.exports = environment

tailwind.config.js

const defaultTheme = require('tailwindcss/defaultTheme')

module.exports = {
purge: [],
theme: {
extend: {
colors: {
blue: {
'100': '#D8F0F9',
'200': '#B1E1F4',
'300': '#8AD2EF',
'400': '#63C3EA',
default: '#3CB5E5',
'600': '#36A2CE',
'700': '#3090B7',
'800': '#2A7EA0',
'900': '#246C89',
},
},
},
},
variants: {
textColor: ['responsive', 'hover', 'focus', 'visited', 'disabled'],
backgroundColor: ['responsive', 'hover', 'focus', 'active', 'disabled'],
borderColor: ['responsive', 'hover', 'focus', 'active', 'disabled'],
},
plugins: [],
}

Error:

ERROR in ./node_modules/emoji-mart/css/emoji-mart.css (./node_modules/css-loader/dist/cjs.js??ref--6-1!./node_modules/postcss-loader/src??ref--6-2!./node_modules/emoji-mart/css/emoji-mart.css)
Module build failed (from ./node_modules/postcss-loader/src/index.js):
TypeError: Invalid PostCSS Plugin found at: plugins[5]

(@/Users/stephensizer/Workspace/coach-rx/postcss.config.js)
at /Users/stephensizer/Workspace/coach-rx/node_modules/postcss-load-config/src/plugins.js:72:15
at Array.forEach ()
at plugins (/Users/stephensizer/Workspace/coach-rx/node_modules/postcss-load-config/src/plugins.js:58:13)
at processResult (/Users/stephensizer/Workspace/coach-rx/node_modules/postcss-load-config/src/index.js:33:14)
at /Users/stephensizer/Workspace/coach-rx/node_modules/postcss-load-config/src/index.js:94:14
@ ./node_modules/emoji-mart/css/emoji-mart.css 2:26-138
@ ./app/javascript/src/components/Conversations/Conversation/Conversation.js
@ ./app/javascript/src/store/reducers/conversations.js
@ ./app/javascript/packs/index.jsx

ERROR in ./node_modules/react-dates/lib/css/_datepicker.css (./node_modules/css-loader/dist/cjs.js??ref--6-1!./node_modules/postcss-loader/src??ref--6-2!./node_modules/react-dates/lib/css/_datepicker.css)
Module build failed (from ./node_modules/postcss-loader/src/index.js):
TypeError: Invalid PostCSS Plugin found at: plugins[5]

(@/Users/stephensizer/Workspace/coach-rx/postcss.config.js)
at /Users/stephensizer/Workspace/coach-rx/node_modules/postcss-load-config/src/plugins.js:72:15
at Array.forEach ()
at plugins (/Users/stephensizer/Workspace/coach-rx/node_modules/postcss-load-config/src/plugins.js:58:13)
at processResult (/Users/stephensizer/Workspace/coach-rx/node_modules/postcss-load-config/src/index.js:33:14)
at /Users/stephensizer/Workspace/coach-rx/node_modules/postcss-load-config/src/index.js:94:14
@ ./node_modules/react-dates/lib/css/_datepicker.css 2:26-145
@ ./app/javascript/src/components/Planning/ShortTermPlanForm/ShortTermPlanForm.js
@ ./app/javascript/src/components/Planning/Planning.js
@ ./app/javascript/src/router/Index.js
@ ./app/javascript/src/components/App.js
@ ./app/javascript/packs/index.jsx

ERROR in ./node_modules/tippy.js/dist/tippy.css (./node_modules/css-loader/dist/cjs.js??ref--6-1!./node_modules/postcss-loader/src??ref--6-2!./node_modules/tippy.js/dist/tippy.css)
Module build failed (from ./node_modules/postcss-loader/src/index.js):
TypeError: Invalid PostCSS Plugin found at: plugins[5]

(@/Users/stephensizer/Workspace/coach-rx/postcss.config.js)
at /Users/stephensizer/Workspace/coach-rx/node_modules/postcss-load-config/src/plugins.js:72:15
at Array.forEach ()
at plugins (/Users/stephensizer/Workspace/coach-rx/node_modules/postcss-load-config/src/plugins.js:58:13)
at processResult (/Users/stephensizer/Workspace/coach-rx/node_modules/postcss-load-config/src/index.js:33:14)
at /Users/stephensizer/Workspace/coach-rx/node_modules/postcss-load-config/src/index.js:94:14
@ ./node_modules/tippy.js/dist/tippy.css 2:26-133
@ ./app/javascript/src/components/Client/ClientSidebar/ClientSidebar.js
@ ./app/javascript/src/hoc/coach_layouts/ClientLayout/ClientLayout.js
@ ./app/javascript/src/router/Index.js
@ ./app/javascript/src/components/App.js
@ ./app/javascript/packs/index.jsx

ERROR in ./node_modules/react-images-upload/index.css (./node_modules/css-loader/dist/cjs.js??ref--6-1!./node_modules/postcss-loader/src??ref--6-2!./node_modules/react-images-upload/index.css)
Module build failed (from ./node_modules/postcss-loader/src/index.js):
TypeError: Invalid PostCSS Plugin found at: plugins[5]

(@/Users/stephensizer/Workspace/coach-rx/postcss.config.js)
at /Users/stephensizer/Workspace/coach-rx/node_modules/postcss-load-config/src/plugins.js:72:15
at Array.forEach ()
at plugins (/Users/stephensizer/Workspace/coach-rx/node_modules/postcss-load-config/src/plugins.js:58:13)
at processResult (/Users/stephensizer/Workspace/coach-rx/node_modules/postcss-load-config/src/index.js:33:14)
at /Users/stephensizer/Workspace/coach-rx/node_modules/postcss-load-config/src/index.js:94:14
@ ./node_modules/react-images-upload/index.css 2:26-127
@ ./node_modules/react-images-upload/compiled.js
@ ./app/javascript/src/components/Account/Info/Info.js
@ ./app/javascript/src/components/Account/Account.js
@ ./app/javascript/src/router/Index.js
@ ./app/javascript/src/components/App.js
@ ./app/javascript/packs/index.jsx

ERROR in ./app/javascript/stylesheets/application.scss (./node_modules/css-loader/dist/cjs.js??ref--7-1!./node_modules/postcss-loader/src??ref--7-2!./node_modules/sass-loader/dist/cjs.js??ref--7-3!./app/javascript/stylesheets/application.scss)
Module build failed (from ./node_modules/postcss-loader/src/index.js):
TypeError: Invalid PostCSS Plugin found at: plugins[5]

(@/Users/stephensizer/Workspace/coach-rx/postcss.config.js)
at /Users/stephensizer/Workspace/coach-rx/node_modules/postcss-load-config/src/plugins.js:72:15
at Array.forEach ()
at plugins (/Users/stephensizer/Workspace/coach-rx/node_modules/postcss-load-config/src/plugins.js:58:13)
at processResult (/Users/stephensizer/Workspace/coach-rx/node_modules/postcss-load-config/src/index.js:33:14)
at /Users/stephensizer/Workspace/coach-rx/node_modules/postcss-load-config/src/index.js:94:14
@ ./app/javascript/stylesheets/application.scss 2:26-228
@ ./app/javascript/packs/application.js

Is there a way to check to see if the notification already exists before adding another as I'm getting a lot of duplicates.

Posted in Action Mailbox Routes

@chris Legend!! Thanks sir!

Posted in Action Mailbox Routes

I'm adding action mailbox to my Rails + React app, the problem I'm having is that the mounted routes are at the very bottom of the routes file so it will not get called due to the fact that I need a catch all for my react app.

Is there a way to move the mailbox routes to the top of the file?

Posted in User model guidance

Hi All,

I'm creating a coaching app and have two users that use the system a coach and a client. A coach can also be a client of another coach. So I will need to be able to switch accounts to either the client or the coach.

Coach:
has_many :clients

Client:
belongs_to :coach

What would be the best way to do this? Having two Devise models Coach and Client or having two boolean fields on the user to say is_coach, and is_client.

If a coach has an account and then is added as a client, I want that client account to have the same password as the coach account for ease of use.

Thanks,
Stephen

Posted in Announcements

Hi Chris,

How do you do the announcements in Hatchbox?

Thanks,
Steve

Posted in Plan limits

I'm currently building a sass product that has three plans beginner, intermediate and advanced. This is then linked to a stripe subscription product.

Each plan has limits eg. the number of team members they can add, the number of projects they can create.

Whats the best way to handle the plan limits?

Posted in File uploads in Rails with Shrine Discussion

has anyone used Shrine and Backblaze B2 storage?

What is the syntax for querying a boolean value?

Trying the below doesn't seem to work? and throws the following error:

PG::UndefinedFunction: ERROR: operator does not exist: text = boolean

current_user.companies.where("holiday_request_settings ->> :key = :value", key: "enable_holiday_requests", value: true)

If I try the following I get no results:

current_user.companies.where("holiday_request_settings ->> :key = :value", key: "enable_holiday_requests", value: "true")

The company current has the following data:

holiday_request_settings: {"enable_holiday_requests"=>true, "holiday_allowance_days"=>20}

This is the code on the model:

typed_store :holiday_request_settings, coder: JSON do |s|
        s.boolean :enable_holiday_requests, default: false
        s.integer :holiday_allowance_days
end

Any ideas?

Posted in How do I work out time slots greater than 5 hours

Thanks Chris

Posted in How do I work out time slots greater than 5 hours

I have a booking application where you can book time against a room. I need a way to find where it is booked for more than 5 hours consecutively to do some reporting.

This can be anytime over a 24 hour period.

So for example it might be booked

Monday
8:00am - 10:00am (2 hours)
10:00am - 13:30pm (3.5 hours)

This should be classed as over 5 hours consecutively.

There could be an occasion where it would be booked like this:

Monday
10:00pm - 12:00am (2 hours)
Tuesday
12:00am - 4:00am (4 hours)

Again this is over 5 hours consecutively

My Models are the following (simplified):

Room

  • has_many timeslots

TimeSlot

  • start_time (:date_time)
  • end_time (:datetime)

I am currently looping through each day of the week and looping through each time slot for that day and then checking to see if start_time == end_time of the next slot to work out if it is consecutive. Not sure if this is the easiest way or if there is something more obvious that would do what I need.

Your help is really appreciated.

Posted in Devise Masquerade with multiple Devise User Models

Hi All,

Has anyone used devise masquerade before with multiple devise models. I have and Admin model and a User model.

I'm having issues and when I try implementing it, I can't seem to login as another user.

Thanks in advance.

Posted in Deliver Later not working

Hi Guys,

I have a rails app, and for some reason when I call deliver_later the emails aren't sending. When I test it with deliver_now it works fine.

I have redis and sidekiq both running.
TID-owqrlmxrh ActionMailer::DeliveryJob JID-10b51cc7e7b76d99307add2c INFO: start

the above shows it goes to the queue but never sends. Any help would be much appreciated before I pull my hair out.

I have written two system tests for my current application and I have now hit a road block.

test "visiting the timesheet index without signing in" do
    visit timesheets_path

    assert_text "You need to sign in or sign up before continuing."
  end

  test "visiting the timesheet index (signing in first)" do
    visit new_user_session_path

    fill_in "Email address", with: "paul@contractor.com"
    fill_in "Password", with: "password"

    click_on "Log in"

        assert_text "Signed in successfully."
  end

The second test is failing due to not being able to load a font shown below:

Error:
ContractorTimesheetsTest#test_visiting_the_timesheet_index_(signing_in_first):
ActionController::RoutingError: No route matches [GET] "/fonts/fa-solid-900.woff2"

If I spin up my rails server locally I have no errors for missing resources and my font files are all loaded correctly.

For further reference I am using the defaults for my application system test case

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
end

Does anyone have any suggestions?