The release of React v18.0 has just been announced. With it comes a number of new features. I won’t go into details about them all, but I want to mention a few that caught my attention.
I have written about this or similar topics before in both Post-Deployment script on Elastic Beanstalk: Restart Delayed Job as well as Convenient way to run app commands in Elastic Beanstalk.
It is quite common to execute multiple queries in a controller action. Just as an example, there might be a dashboard that displays data from multiple models or scopes.
Rails 7 adds Enumerable#maximum and Enumerable#minimum methods to easily calculate the maximum or minimum from extracted elements. These methods have existed in ActiveRecord for some time now and is useful when you have a collection of records.
It looks like a new syntax for declaring enums in your models has been introduced. Instead of passing the name and values as a key/value pair, it can now be passed as two separate arguments instead. Not a big change in itself but what this enables is in my opinion a more intuitive way to pass additional options.
When it comes to working with a mix of values or variables, and I want to treat them as an array, I am in the habit of using the
Array(...) method to make sure I am always working with an array, without having to explicitly check for a nil or non-array values. What this method does is that it tries to call first
#to_a on the passed argument.
Scoping in Ruby on Rails allows us to define frequently used queries which can be invoked as method calls on either association objects, relations or models. You can reference the standard query methods like
includes. The requirements of defined scopes is that it must return either an instance of
nil. This allows us to chain multiple scopes together for highly flexible query construction.
I recently went about cleaning up some of my earlier “syntax mistakes” in a Ruby project of mine. So what do I mean by syntax mistake? It is a term I use to define something that works perfectly fine, but leaves you with that feeling of “shouldn’t there be a nicer way of writing this?”. I think you know the feeling.
I have previously written a post about Find or create by and its usages in Rails 3 but Rails have gotten several version updated since then and some of the things I mentioned have even been deprecated at this time, so I wanted to revisit this very useful method again.
Elastic Beanstalk is great! It is very easy to get a Rails app up and running on AWS quickly. Perfect for an app developer that prefers not to deal directly with sysops but still wants to deploy to and leverage the services on AWS.
When the need arise to SSH into your EB instance and execute a command in your app, you might run into issues. I describe in an earlier post how to trigger a restart of DelayedJob after each deployment. In that particular case, one issue was that the command was not running under the correct ruby installation. Turns out that we can make use of EB’s own support scripts to help us out.
I have written before about the method
find_or_create_by, so what is different about this new addition and why is it needed?
When writing controllers in Ruby on rails, using
before_action (used to be called
before_filter in earlier versions) is your bread-and-butter for structuring your business logic in a useful way. It’s what you want to use to “prepare” the data necessary before the action executes.
I feel like I have been neglecting my own site for far too long. It really was time to change the layout of it to match the expectations of recent web layout standards. For a while now, everyone has been talking about responsive design and mobile first. So I figured it was time to apply it here as well.
This is not gonna be any news for a lot of people out there, but I recently discovered the beauty of the git command
stash. And even though I feel a little embarrassed about the fact that I did not discover it earlier, I decided to post a quick note about it.
UPDATE 2018! Paperclip is deprecated
I have been using Vagrant for a while now. Overall I am very satisfied with the simplicity of it and the way it can standardize environments when it comes to collaborating with others. In my bigger projects I usually setup a
Vagrantfile.example with all the default settings that I commit to the git repository and then I add an exception for the Vagrantfile itself to allow for personal customization if that would be needed.
This is a guide on how to get up and running with Node.js on Mac OS X. The purpose of this tutorial is to be a reference post for other tutorials because when you have done it once, then you will probably not need to do it again. So I feel it’s unnecessary to include it all the time. Plus, it’s probably very basic for most of you.
The Node.js module called express has now released its 3.0.0a version. For me, express is one of the packages that I always use in my node projects. It’s so easy to get up and running with it and there are tons of examples and tutorials (many outdated unfortunately) from where you can get answers and inspiration.
I have been playing around with Node.js on and off now for quite some time. And one thing that have bothered me is the simple fact that I had to restart the node server process every time I made the slightest changes to any server side code. Normally I would have given up much earlier and start looking for a way to get around it. But since I never really stuck with Node for any longer period of time, I never got to it.
This release offers some cool updates. It’s clear that everybody is concerned about what happened at GitHub a while back, when someone managed to access everybodys ssh keys by using mass-assignment to change his permission. So it’s nice to see that the Rails community is addressing this. I really like that the auto-generated ActiveRecord models have been updated to show the importance of attr_accessible. Since a lot of people who are using rails can be fairly new to developing. For some it might even be the first thing the try. So unless they understand the risks, they might end up with an application with some serious security risks.
Yehuda Katz has started a KickStarter project were he explains his plans to develop an .app for Mac OS X that will be used to quickly get up and running with Rails. He mentions how it used to be (in the good old days) and goes on to describe what this project will accomplish. The pledge goal for the project is set to $25,000.