820 Experience
7 Lessons Completed
0 Questions Solved


Posted in Video explaining notifications-rails

Hey Chris,

I was wondering if you could do a video on the gem 'notifications-rails'? I like their approach, as it's broken down into 4 main components: NotificationHandler, NotificationRenderer, NotificationSetting, and NotificationPusher.

The problem is the documentation is rather sparse and, while I did get the notifications to create and render (which took awhile on its own), any time I try to add additional features I end up running into a number of errors.

If used correctly, however, I think this seems to be one of the more flexible and popular notification systems for Rails, as it also takes care of User preferences and subscriptions too. Maybe it could also be added to Jumpstart Pro? A lot of users are asking for a built-in, configurable notification system there, so it may be worth looking into (unless there is another gem you've had your eye on).

I'm interested in hearing your thoughts about this. Thanks!

Posted in How to use ActionText in Rails 6 Discussion

Perfect! Wasn't aware about min-height. Thanks!

Posted in How to use ActionText in Rails 6 Discussion

How can I customize the default size of the rich_text_area field, so that it displays longer vertically even before anything is typed in, and still retain the height: auto; scaling feature?

It doesn't seem like rich_text_area has any parameters like the regular text_area has.

Here is what I have so far:

<div class="form-inputs">
    <%= f.form_group :body, class: 'row' do |f| %>
      <%= f.label :body, class: 'control-label col-md-2' %>
      <div class='col-12 col-md-10'>
        <%= f.rich_text_area :body, class: 'form-control' %>
        <%= f.error_messages %>
    <% end %>
trix-editor {
  &.form-control {
    height: auto;

.form-control {
  .attachment--preview {
    margin: 0.6em 0;

  .attachment--preview {
    width: 100%;
    text-align: center;

  .attachment {
    display: inline-block;
    position: relative;
    max-width: 100%;
    margin: 0;
    padding: 0;

In my app, I have several models for various product types, as each product has different attribute types and I wanted to avoid using STI. However, I am using the same Review and Comment system for each of the Product resources. So for example, a path would be accessories/1/reviews/1/ and the New Comment form (and all comments for that review) will display under the specific Review.

I am taking the same approach as used in the following video:

Right now, the New Comment form displays properly below the show review page, but when I try to create a new comment I receive the following error:

NameError at /accessories/1/reviews/1/comments
uninitialized constant Accessories::Reviews
activesupport ( lib/active_support/inflector/methods.rb
279 280 281 282 283 284 285 286 287 288 289
      names.inject(Object) do |constant, name|
        if constant == Object
          candidate = constant.const_get(name)
          next candidate if constant.const_defined?(name, false)
          next candidate unless Object.const_defined?(name)

Here is all the relevant code I have:


      <%= render partial: "comments/form", locals: { reviewable: @reviewable, commentable: @review } %>
      <%= render partial: "comments/comments", locals: { reviewable: @reviewable, commentable: @review } %>

views/comments/_form.html.erb :

<%= form_for([reviewable, commentable,]) do |f| %>
          <%= f.form_group :body, class: 'row' do |f| %>
            <div class='col-12 col-md-12'>
              <%= f.text_area :body, { class: 'form-control', placeholder: "Add a comment..." } %>
              <%= f.error_messages %>
          <% end %>
          <div class="d-flex">
        <div class="ml-auto">
                    <%= f.submit class: "btn btn-primary pull-right" %>
        <% end %>


class Accessories::ReviewsController < ReviewsController
    before_action :set_reviewable
    before_action :show_reviewable

    # GET /reviews
  def index
    @reviews = Review.where(reviewable_type: "Accessory", reviewable_id: params[:accessory_id])


        def set_reviewable
            @reviewable = Accessory.find(params[:accessory_id])

        def show_reviewable
            @show_reviewable = Review.find_by_reviewable_type_and_reviewable_id("Accessory", params[:accessory_id]) 


class Reviews::CommentsController < CommentsController
    before_action :set_commentable


        def set_commentable
            @commentable = Review.find(params[:review_id])


class CommentsController < ApplicationController
    before_action :authenticate_user!
    def create
        @comment =
        @comment.user = current_user
        redirect_to @commentable, notice: "Your comment was successfully posted!"


        def comment_params


  resources :accessories do 
    resources :reviews, module: :accessories do
      resources :comments, module: :reviews


class Accessory < ApplicationRecord
  belongs_to :user
  #has_rich_text :body
  has_many :reviews, as: :reviewable, dependent: :destroy
  #has_many :comments, as: :commentable, through: :reviews

  accepts_nested_attributes_for :reviews
  #accepts_nested_attributes_for :comments


class Review < ApplicationRecord
  belongs_to :user
  belongs_to :reviewable, polymorphic: true
  has_rich_text :body
  has_many :comments, as: :commentable


class Comment < ApplicationRecord
  belongs_to :user
  belongs_to :commentable, polymorphic: true

Appreciate any guidance. Also, if there is a more efficient way to do this please let me know. Thanks!

logo Created with Sketch.

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

© 2023 GoRails, LLC. All rights reserved.