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.
Ruby on Rails
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.
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.
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.
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.
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.
Ruby on Rails is a popular web application framework that has been used by developers for over a decade. It has a reputation for being easy to learn and use, and for providing developers with a lot of tools and features to build robust web applications.
ActiveRecord has a lot of callbacks but probably one of the most frequently used ones is
before_save. There are a few other ones that are very similar like
before_update, but they are just more narrowly scoped callbacks hat otherwise does the same thing.
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.
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.
In the Model-View-Controller (MVC) architecture, the Model is responsible for representing the data and the business logic of an application. In Ruby on Rails, the Model is implemented using the ActiveRecord pattern, which is a powerful and easy-to-use ORM (Object-Relational Mapping) tool. In this article, we will explore the Model part of MVC in Rails and provide code examples to illustrate its usage.
When developing a web application with Ruby on Rails, it is common to create associations between different models. Among the most important associations in Rails is the
belongs_to method, which establishes a one-to-many relationship between two models.