Activity
I'd guess that p[robably is coming from this command (line 10) https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/rails/rails.plugin.zsh#L1
I'm not quite sure why it isn't finding the rails command though. Maybe the Rails command isn't in your PATH in ZSH and when you load bash it updates your PATH?
Have you added rbenv's stuff into your .zshrc? That's probably it if I had to guess.
There are many ways to talk to an API. HTTParty, RestClient, etc are all options you could use.
That's really cool, thanks for sharing!
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.
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.
Awesome! Good luck with your new job!!
Hey Kelvin,
I did a couple episodes on caching and Redis:
https://gorails.com/episodes/russian-doll-caching-with-rails-5
https://gorails.com/episodes/gorails-performance?autoplay=1
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"
Those will be covered shortly! Just want to finish up this series real fast first. :)
Yeah, I do see the same thing. Will take a look at a fix for it.
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.
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!
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.
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