At Codemancers, we believe every day is an opportunity to grow. This section is where our team shares bite-sized discoveries, technical breakthroughs and fascinating nuggets of wisdom we've stumbled upon in our work.
Published
Author
Satya
ActiveSupport::CurrentAttributes provides a thread-isolated attributes singleton, perfect for request-specific data like current user, role, or locale. create a current.rb in models directory and add the attributes we want to set
Ruby
class Current < ActiveSupport::CurrentAttributes attribute :roleend
then in application controller we can set it like this
Code
class ApplicationController < ActionController::Base before_action :set_current_attributes def set_current_attributes Current.role = session[:role] // ... other attributes endend
now in your application we can directly access and use like Current.role
#CU6U0R822 #rails-current-attributes
Published
Author
Aditya Vishwakarma
System Analyst
Mise
Mise is a fast, lightweight (thanks to Rust :happy_pepe:), language agnostic version manager that can be used instead of having separate language based version managers like rbenv for Ruby, npm for Node.js and Pyenv for Python etc.
Installing a Ruby version globally is as simple as follows:
rust
mise use -g ruby@3
Installing mise is as easy as following in MacOS
Ruby
curl https://mise.run | sh
Proceed with following to configure the Shell Initialisation
mattr_accessor is a Rails utility method that creates a class-level accessor for a variable. When we define mattr_accessor for a variable, it creates 1. A getter method for the class. 2. A setter method for the class. Eg:
Ruby
class MyClass mattr_accessor :my_variableend
This is equivalent to:
Code
class MyClass @my_variable = nil def self.my_variable @my_variable end def self.my_variable=(value) @my_variable = value endend
It also works on module-level classes, which makes it particularly useful for defining global configuration in gems.
#CU6U0R822
Published
Author
Ayush Srivastava
System Analyst
accepts_nested_attributes_for is a Rails method that allows you to easily manage the creation, updating, and destruction of associated models through the parent model's attributes. This is particularly useful when you have nested forms or when you want to handle multiple models in a single operation (e.g., creating or updating a User and its associated Profile in one form submission).
Ruby
class User < ApplicationRecord has_one :profile accepts_nested_attributes_for :profileend
Given the User model has a has_one :profile association, and you want to create or update a User and their Profile at the same time, you can use accepts_nested_attributes_for to pass attributes for both models:
In this example, Rails will create both a new User and a new Profile with the attributes provided in profile_attributes. #CU6U0R822
Published
Author
Syed Sibtain
System Analyst
When working with paginated data in Ruby on Rails, we might encounter situations where we need to paginate an array rather than an Active Record collection. The pagy gem provides an efficient and flexible way to handle pagination, and it includes an extras/array feature specifically for arrays.
Output: dir(obj) shows a list of attributes (class_variable, instance_variable) and methods (my_method), along with special methods (e.g., __init__). It helps explore what’s available in an object.
Published
Author
Nisanth
Test SSH connection detailed logs to debug #ssh #CCTJN6PK4
Code
ssh -vT "git@gitlab.com"
This will output detailed logs
Published
Author
Ashwani Kumar Jha
Senior System Analyst
Definite Assignment Checks in TypeScript 5
• Before TypeScript 5:
TypeScript
let value: string;console.log(value); // TS4.x: This was allowed but could lead to runtime undefined
• After TypeScript 5:
Code
let value: string;console.log(value); // TS5.x: Error - Variable 'value' is used before being assigned// To fix, either initialize:let value = "initial";// Or use definite assignment assertion:let value!: string;
• The ! is a promise to TypeScript that we'll assign a value before using it • Use of ! should be avoided as it bypasses TypeScript's safety checks
Published
Author
Nived Hari
System Analyst
When working with routes in a Rails application that includes an engine, route references need to be scoped appropriately based on where they are being called: • Referencing engine routes from outside the engine: Prefix the route with the engine's name. For example, use engine_name.some_route_path (e.g., rapidfire.surveys_path) to access routes within the engine. • Referencing routes from another engine: Use the other engine's name as a prefix, similar to referencing routes from outside. This naming ensures the correct routing context and prevents conflicts when multiple engines or the main application define similar paths.
#CU6U0R822 #routes
Published
Author
Nived Hari
System Analyst
Form Objects in Rails Form objects are a pattern that is used to encapsulate logic for managing and validating form data. They act as an intermediary between the view and the model layer, they simplify the handling of complex forms, particularly when working with complex forms that don't map to a single active record model. Why use form objects? In typical rails applications, forms are directly tied to active record models. This is ok when the forms are simple, but this can cause problem when complexity increases such as, when forms interact with multiple models In these kind of scenarios, we can encapsulate the corresponding logic into a single class which acts like an active record model which is easier to maintain.
Example form object app/forms/route_request_form.rb
Ruby
class UserProfileForm include ActiveModel::Model # Attributes accessible for the form object. attr_accessor :user_name, :email, :profile_bio, :profile_age validates :user_name, :email, presence: true validates :profile_age, numericality: { only_integer: true, greater_than: 0 } def save return false unless valid? #a single transaction for multiple operations ActiveRecord::Base.transaction do user = User.create!(name: user_name, email: email) user.create_profile!(bio: profile_bio, age: profile_age) end true # Return true if all operations succeed. rescue ActiveRecord::RecordInvalid false # Return false if the save process fails. endend
Using it in controller
Code
class UsersController < ApplicationController def new @form = UserProfileForm.new end def create @form = UserProfileForm.new(user_profile_form_params) if @form.save redirect_to root_path, notice: "User created successfully!" else render :new, status: :unprocessable_entity end end private def user_profile_form_params params.require(:user_profile_form).permit(:user_name, :email, :profile_bio, :profile_age) endend
#ruby_on_rails #form_objects
Showing page 11 of 83
Your competitors are already using AI. The question is how fast you want to unlock the value.
Don't know where to start?
AI is everywhere but it's unclear which investments will actually move your metrics and which are expensive experiments.
Your data isn't ready
Most AI projects fail at the data layer. Pipelines, quality, access all need work before LLMs can deliver value.
Internal teams are stretched
Your engineers are shipping product. They don't have capacity to also become AI specialists with production-grade experience.
Legacy systems block everything
Aging, undocumented codebases make AI integration slow, risky, and expensive. They need to move first.