15 Followers
21 Following
41 Posts
Senior Ruby on Rails Developer. | Open for new roles.
Contacthttps://haseebeqx.com
LinkedInhttps://www.linkedin.com/in/haseeb-a-45590868/
BirdSitehttps://x.com/Haseebeqx
Githubhttps://github.com/haseebeqx

I created a RailsByte template for #Rails8 authentication generator user registration feature. This makes it easy to generate full authentication and registration. Includes optional email confirmation feature.
Here is how to do it:
```
gem install rails -v 8.0.0.beta1
rails new auth-test
cd auth-test
rails generate authentication
rails app:template LOCATION='https://railsbytes.com/script/Xg8sMD'
```
Source: https://railsbytes.com/public/templates/Xg8sMD

This acts as a starting ground for implementing full authentication

With #Rails, Even loading DB dump has a Rails way.
#Rails Tip: You can use Rails attributes API in value objects to make use of built-in parsing. This is applicable in some usecases. Also added a blog post in this topic http://haseebeqx.com/posts/lets-start-using-attributes-api/
Let's Start Using Rails Attributes Api | Haseeb A

When building applications in Ruby on Rails, We store data in Plain Old Ruby Object (called PORO) value objects. This is a common pattern, We store data directly in service objects using attr_accessor. But in some cases we might have to cast data from string. For this, we do have to cast those attributes. Traditional approach 🔗class Product attr_accessor :name, :price, :released_at, :in_stock def initialize(attributes = {}) @name = attributes[:name] @price = parse_price(attributes[:price] || '0') @released_at = parse_datetime(attributes[:released_at]) @in_stock = parse_boolean(attributes[:in_stock]) end private def parse_price(value) BigDecimal(value.

In #Rails we can use `ActiveRecord::Base.connected_to` for managing multiple databases dynamically on the fly.
Here is an example of a fictional e-commerce application that uses separate databases for handling product information and user accounts. `role` and `shard` can be set.

Today's #rails tip is about how to add temporary query methods to an ActiveRecord::Relation object on the fly.

`ActiveRecord::Relation#extending` method allows you to create custom query methods that are specific to a particular scope or context

Today's #Rails tip is about the `suppress` feature, which can be useful when you want to skip callbacks. Here is a madeup scenario to explain it.
Today's #rails tip is about `ActiveSupport::Configurable`. It is useful for adding configuration options to your classes or modules, It is exactly similar to how Rails is configured.
#Rails tip
Did you know you could add some validations in nested attributes? The `reject_if` option lets you specify conditions under which nested attributes should be ignored. It will silently ignore new record hashes if they fail to pass your criteria. You can also pass a symbol. For example `:new_record?`.
Tip: In #rails, The `with_options` method can be used to group common options for a set of method calls to avoid repetition. It is useful in model validations, associations, or any other configuration that involves multiple methods with the same options.
Here are some examples
#Rails tip:
The `composed_of` method allows us to create value objects from database columns, providing a way to encapsulate related attributes and behavior. Good for clean code. Attaching an example below. For more information see https://api.rubyonrails.org/classes/ActiveRecord/Aggregations/ClassMethods.html
ActiveRecord::Aggregations::ClassMethods

Active Record Aggregations Active Record implements aggregation through a macro-like class method called composed_of for representing attributes as value objects.