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
Ashwani Kumar Jha
Senior System Analyst
A Lambda layer in AWS Lambda is a feature that lets us manage and share common code and libraries across multiple Lambda functions. By creating a Lambda layer, we can package common code in its own module, which can then be used by our Lambda functions. This reduces duplication and simplifies the management of shared code.
Published
Author
Adithya Hebbar
System Analyst
We can generate a base64-encoded random key easily using either openssl or a combination of dd and base64. Here's how:
Migration: Remove old image columns if switching from direct storage to Active Storage. #CU6U0R822 #activestorage #fileupload
Published
Author
Adithya Hebbar
System Analyst
To logout from Keycloak using the signOut function in NextAuth, you need to override the default behavior to ensure that the user is properly logged out from Keycloak as well. Here's how you can update your signOut function:
I encountered a scenario where I needed to retrieve the scope of one policy and use it within another policy. Specifically, I wanted to delegate permissions from one policy to another.
To address this issue, I learned to use Pundit's methods for manually retrieving policies and scopes: • Retrieving a Policy
Code
Pundit.policy(user, record) # Returns nil if the policy does not existPundit.policy!(user, record) # Raises an exception if the policy does not exist
• Retrieving a Policy Scope:
Code
Pundit.policy_scope(user, ModelClass) # Returns nil if the policy scope does not existPundit.policy_scope!(user, ModelClass) # Raises an exception if the policy scope does not exist
These methods allowed me to delegate permissions effectively by retrieving and applying the appropriate scopes and policies
#rails #pundit #pundit-policy #authorization
Published
Author
Syed Sibtain
System Analyst
Quick Tip: How can we open a PR from one repository to another repository
3. Push the new branch to the destination repository
Code
git push destination new-branch
4. To check all the remote repositories added, we can do:
Code
git remote -v
Then, we create a PR in the destination repository from the new branch. This process effectively copies the changes from the original PR into a new PR in a different repository.
#github #git
Published
Author
Sujay
Rails templates accept any locals as arguments. However, starting from Rails 7.1, we can restrict which locals a template must accept using "Strict Locals".
I wonder who in the world wrote this snippet!!! :)
#javascript #browser
Published
Author
Syed Sibtain
System Analyst
Ransack adds several class methods to ActiveRecord::Base for managing search and sort capabilities. These methods allow us to define which attributes, associations, and scopes are accessible through Ransack queries, thus enhancing security and control.
ransackable_attributes: Defines which model attributes can be used in Ransack searches. For example, only the order_number, status, and business_unit fields can be used in Ransack searches.
Code
def self.ransackable_attributes(auth_object = nil)%w[order_number status business_unit] end
ransackable_associations: Specifies which model associations are accessible for searching. For examle, only the customer and vendor associations are allowed for searching.
Code
def self.ransackable_associations(auth_object = nil)%w[customer vendor] end
ransortable_attributes: Lists which attributes can be used for sorting results. In this example, sorting is allowed only by order_number and created_at
Code
def self.ransortable_attributes(auth_object = nil)%w[order_number created_at] end
ransackable_scopes: Determines which custom scopes can be applied in searches.
#rails #ransack #search
Showing 17 to 19 of 82 results
Ready to Build Something Amazing?
Codemancers can bring your vision to life and help you achieve your goals