Chris Oliver

Joined

292,890 Experience
93 Lessons Completed
295 Questions Solved

Activity

Posted in Vue.js Trello Clone in Rails - Part 7 Discussion

Yeah, I do see the same thing. Will take a look at a fix for it.

Posted in Rails & Vue.js Trello Clone - Part 1 Discussion

Yeah, I have a really basic template that installs Bootstrap, Devise, and Administrate. It's really nothing more than if you install those gems yourself and create a root page. I'll publish it sometime soon once I fix a couple bugs in it.

cc @mikemcclintock:disqus

Sounds like you messed up your PATH variable. You might try:

export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

That should reset you somewhere normal and then you can go fix your bash profile.

Posted in Rails & Vue.js Trello Clone - Part 4 Discussion

Yeah, that is true since we don't use it really anywhere else. 👍

That could be good beginner content, and possibly a place to begin talking about testing. Both more beginner topics and testing are goals for me to cover more in 2018. 👍

I would suggest starting with the very first episodes. https://gorails.com/episodes?page=23

Those are some basics about Ruby on Rails then it gets into building a lot of basic features most apps have like login, permissions, likes, etc.

If you're completely new to Rails, GoRails might be a little much at the beginning and I would suggest going through the Rails tutorial as well: https://www.railstutorial.org/book

That said, if you have any questions on things or a topic you would like covered, just let me know and I'll try my best to make some screencasts for you!

Posted in Vue.js Trello Clone in Rails - Part 7 Discussion

Thanks Josh! I'm actually finishing up an episode adding realtime updates to the Trello clone with Vuex and ActionCable. Should be out in the next week or two!

Hey Robert,

That's a great question. The answer to this isn't super obvious. When you'd normally just do a COUNT, you can't do that without counting each of the related ones and then sum all those up. The more nested things get, the slower this becomes.

One solution I would suggest is to build your own counter cache here manually. Instead of using Rails for it, you can add a comments_count integer field to your model and then add callbacks to increment and decrement this number on create and destroy. That will work similar to the Rails counter cache like I mentioned, but you'll loop through till you find the parent object to increment.

For example, with nested comments, you'd have model associations that look like this

Post -> Comment -> Comment -> Comment

When you create that last comment, you need to loop up through the parents until you get to the Post. This won't be a Comment model, so we can check the commentable_type column to see if we've gone up the stack far enough to find that model.

This is just psuedo code, so you'll probably have to change it to be make it work, but roughly the idea would be this:

class Comment
  belongs_to :commentable

  after_create :increment_count
  after_destroy :decrement_count

    def increment_count
      parent = commentable

        # Keep looping until we get to the parent which isn't a Comment model
        while parent.is_a? Comment
          parent = parent.commentable
        end
        parent.increment! :comments_count
    end

    def decrement_count
        parent = commentable

        # Keep looping until we get to the parent which isn't a Comment model
        while parent.is_a? Comment
          parent = parent.commentable
        end
        parent.decrement! :comments_count
    end
end

This will work best on a new app without commenst already because it won't back-fill existing counts. For that, you'd probably want to do something like the "deep_count" method mentioned on SO there, but it only needs to happen once after your counter cache column was added.

Posted in Logger.debug to output command line results

Hey Anand,

For Hatchbox.io, when I do things like setup LetsEncrypt, etc. I use the exit code of the commands to determine success or fail. You probably want to do the same thing here rather than looking at the logs.

There's a special variable Ruby sets called $? after you run a system command that you can check for the exit code of the command you just ran. If it's 0 then the command was successful, non-zero means it failed.

system also seems to return nil, true or false based on the exit status according to the docs: http://ruby-doc.org/core-2.0.0/Kernel.html#method-i-system

system("unknown command")     #=> nil
system("echo foo")            #=> true
system("echo foo | grep bar") #=> false

So that means you could say success = system(command) and check for truthiness to see if it was successful.

You don't have access to that in the model. For assigning current_user, I do that in the controller but all other defaults I'd put in the model.

def create
  @record = Record.new(record_params)
    @record.owner = current_user

    if @record.save
    #... etc
end

Generally, I put default values in the model itself rather than the controller.

class User
  after_initialize :set_defaults

    def set_defaults
      self.email ||= "email@address.com"
    end
end

Posted in Creating usergroups

Hey Trenton,

What you've got is definitely on the right track. The reason being that to create these many to many relationships in SQL is that you have to have the join table in order to have them.

It sounds like you might actually want to put the belongs_to :map on the Group itself so that you can easily add all the group's users to a map.

Also left you a comment on your SO post. 👍

Posted in How do I add opensearch to a Rails app

Hahaha yeah! :P

I got a chance to read this article: https://aaronparecki.com/2011/07/11/3/how-to-let-google-power-opensearch-on-your-website

It looks like your XML file and stuff should match up with what he manually wrote out. I think you should try pushing to production and load up the XML url and make sure it renders properly with the right urls and everything and see if Google picks it up over the next few days. Pretty sure you've got it setup right.

Posted in How do I add opensearch to a Rails app

That's a great question. I've never intentionally added that feature to GoRails, so I don't actually know. :-) In fact, I don't think there's any OpenSearch tags or anything so I wonder if they can detect a standard like /search url or something in my case.

Posted in What are your goals for 2018?

Hey Alan! Glad you started this again. I love doing these.

2017 was really good. I launched HatchBox.io and having my second product up and running has been fantastic experience.

For 2018, my goals are:

  1. Launch a 3rd product to help small businesses get started (I'll be announcing this soon!)
  2. Grow GoRails & HatchBox.io
  3. I want to explore Crystal Lang a lot more and see about building a new web framework with it

Hey Tatiane,

You can do this pretty easily with an after_create callback on the StockFlow model.

Roughly, it'd probably look something like this:

class StockFlow
  after_create :update_stock

    def update_stock
      stock = Stock.find_by(name: name)

        if stock.present?
        case in_out
        when "in"
              stock.update(amount: stock.amount + amount)
          when "out"
              stock.update(amount: stock.amount - amount)
            end

        else
          Stock.create(name: name, amount: amount, kind: kind)
        end
    end
end

Posted in Rails & Vue.js Trello Clone - Part 2 Discussion

I used a thick arrow function which does that for you. You'll see my success function is: "success: (data) => {" and you use "success: function()".

Pretty much exactly what you mentioned. I am working on a video app that I'll be showing off more in the future, but it has a bunch of videos on the page and I wanted to use a Vue app for each one. I just selected all the elements that matched like ".video" and then looped over them and created a new Vue() app for each one. Works like a charm.

You won't need to check if the element exists in this case because it won't run the loop if there are no results so it may be a little more straightforward than selecting by ID which could return you null (and and why we have to check it).

Posted in Rails & Vue.js Trello Clone - Part 1 Discussion

AJAX will always be slower because you're making a second network request and will always force a 'loading' state on the Vue app. I personally hate waiting for widgets to load so I'd rather preload the JSON on the page and have an instantly available frontend.

Posted in Hatch Deploy

You have to setup domains for your apps otherwise your server doesn't know which app to serve and will always just serve the first one.