Chris Oliver

Joined

291,480 Experience
86 Lessons Completed
296 Questions Solved

Activity

Posted in Modern Webpack template on Rails 5.1

Hey Jiri,

I think you're right for the most part. I believe you could just move those assets folders into app/javascript/pack and you'd be able to use reference them from there.

You could probably put it in the vendor folder since you wouldn't really want to edit these files, but that may just require you to import the files into webpacker a bit differently.

You might have to say like import X from '../../vendor/assets/index or whatever. It'll take some experimenting.

I think the vendor folder is the ideal so you aren't tempted to edit any of those files to make updating to newer versions of the template easier. That said, don't let that stop you if you can get it working in app/javascript easier. A running app is more useful than a perfectly organized one. You can always move the files around after you get it working.

I did an episode on that here: https://gorails.com/episodes/consuming-an-api-using-httparty-and-creating-a-gem

It's using the HTTParty gem, but you can also use like RestClient as well which I believe I've talked about in an episode or two as well.

Posted in How can I setup Vim for rails development on Ubuntu?!

I'm using github.com/carlhuda/janus which works on anything. It's close enough with shortcuts to Sublime Text that it was a pretty easy switch.

Just remember, with Vim all you need to learn at the beginning are enough basics to get you going. Then you can take time to learn more complicated things.

Posted in Learn what is Redis and how to use it with Rails

Awesome! Good luck with your new job!!

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

And fixed. The solution is to add the "key" property to the loop so it can differentiate which items have changed.

card v-for="card in list.cards" :key="card.id" :card="card" :list="list"

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

Those will be covered shortly! Just want to finish up this series real fast first. :)

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.