Fueling Curiosity, One Insight at a Time

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.

Oct 11, 2024
Here’s how to update the most recent commit with new changes:

git commit --amend --no-edit command allows you to modify the most recent commit without changing its commit message.

• The --amend flag updates the previous commit with the new changes.
• The --no-edit option keeps the existing commit message unchanged.
After amending the commit, if it has already been pushed to the remote repository, you’ll need to force push the changes using: git push -f

#git #git-commit
adithya.hebbar
Adithya Hebbar
System Analyst
Oct 9, 2024
Symbols shown in build logs for routes specifies-
ƒ: A dynamic function, typically an API route, that runs on the server and is not statically exported.
: A statically generated (SSG) page, built once during the build process.
: A dynamically generated (SSR) page, built at request time.
#build
aman.suhag
Aman Suhag
System Analyst
Oct 9, 2024
Rails Association Callbacks

Rails association callbacks let you hook into the lifecycle events of an associated collection. These callbacks are triggered when objects are added to or removed from the collection.

Available Callbacks:
- before_add: Invoked before an object is added to the collection.
- after_add: Invoked after an object is added to the collection.
- before_remove: Invoked before an object is removed from the collection.
- after_remove: Invoked after an object is removed from the collection.

#associationcallbacks #callbacks #CU6U0R822
giritharan
Giritharan
System Analyst
Oct 9, 2024
"Search-as-You-Type" in Rails with Turbo Frames and Stimulus

Making the search box more interactive can be achieved with simple steps:

We could do this without Turbo by submitting the form whenever an input event occurs, right? No. In that case, on each input, the form gets submitted, and the input field loses focus. This is where Turbo Frames come into play. For this scenario, we need Turbo to reload only the content we want to update while leaving the rest of the page as it is.

For this, we define which part we want to reload based on our search by wrapping that particular section inside a turbo_frame_tag and targeting that Turbo Frame from the search form.

Sample search form:



 <%= form_with(
  url: search_path, method: :get,
  data: { turbo_frame: "frame_id", turbo_action: "advance", controller: "search", action: "input->search#submit" }
) do |f| %>
  <%= f.search_field field_name, placeholder: placeholder, value: params %>
<% end %>


turbo_frame : Points to the specific Turbo Frame we want to update with the search results. It allows us to reload only the content within this frame without affecting the rest of the page.
turbo_action : Defines the behavior of the Turbo request. In this case, it is set to "advance," which means the URL is appended to the previous ones. This allows users to navigate back to previous searches using the browser's back button, maintaining the search history. There are other actions like "restore", "pop" as well.

Example:



<%= turbo_frame_tag "search_results" do %>
       
#This will contain the search results <% end %>


( We will give data : { turbo_frame: "search_results" } in this case )

In this way, when a fetch occurs from the search form, only the part inside the turbo_frame_tag is reloaded. The rest of the page remains untouched, and the form won't lose focus.

For optimization, we can add debouncing also, which can be done in the Stimulus controller.

#RubyOnRails #turbo #turbo_frames
nived.hari
Nived Hari
System Analyst
Oct 9, 2024
Fastest way to put website on internet:

Using Ngrok we can do that easily.

step1: install Ngrok

step2: create account in Ngrok website (for AUTHTOKEN)

step3: run the command in the terminal - ngrok authtoken YOUR_AUTHTOKEN

step4: add the regex in config/environment/development.rb




Rails.application.configure do
    # Other configurations...
    
    # Add your Ngrok URL to the list of allowed hosts 
    config.hosts << /[a-z0-9\-]+\.ngrok-free\.app/
end



step5: start the server and open new terminal then in the project directory run the command ngrok http 3000 . Where 3000 is port number in which localhost is running.

step6: ngrok will give us a link, with that link we can access the website.

Ngrok is not only limited to rails. We can use with any framework.

#CU6U0R822 #ngrok
nitturu.baba
Nitturu Baba
System Analyst
Oct 8, 2024
How to Create a Multi-Language Website in Rails

Ruby on Rails comes with an integrated internationalization (I18n) framework that makes it simple to add multi-language support to your website.

Create Locale Files

You can define your translations using .yml files located in the config/locales directory.
For example, if your website supports English and Hindi, you would create two files: en.yml and hi.yml.

en.yml file:


en:
    hello: "Hello"
    good_morning: "Good Morning %{name}"  # %{name} is used to pass dynamic parameters.
    rails: "Rails"


hi.yml file:


hi:
    hello: "नमस्ते"
    good_morning: "शुभ प्रभात  %{name}"
    rails: "रेल"


Use Translations in Your Views

You can use the t helper method to access translations in your views.



<%= t("hello") %>
// normal usage
<%= t("good_morning", name: t("rails")) %>
// Passing Dynamic Parameters.


Language Switching via URL

The language displayed will depend on the locale set in the URL. For example:
• If the URL is https://localhost:3000/en, the English translation will be used.
• If the URL is https://localhost:3000/hi, the Hindi translation will be used.
#CU6U0R822 #multi-language
nitturu.baba
Nitturu Baba
System Analyst
Oct 7, 2024
A Dead Letter Queue is a special queue in message queue systems that holds messages (payload) that cannot be delivered to their intended recipients due to various reasons.
These reasons can include:

• Incorrect message formatting
• Network errors
• System failures
• Application-level errors
DLQs serve several important purpose.

1. Message Preservation: They prevent loss of messages/payload that fail processing, allowing for later analysis or retry.
2. System Stability: By isolating problematic messages/payload, DLQs prevent failures from affecting the main message flow.
3. Debugging: DLQs provide a centralised location for developers to inspect and diagnose issues with failed messages.
#deadletterqueue #queuemanagement
syedsibtain
Syed Sibtain
System Analyst
Oct 7, 2024
https://Fly.io|Fly.io release_command

In https://Fly.io|Fly.io, the release_command is a special one-time command executed before deploying an app. It’s often used for tasks like running database migrations or other setup steps that need to happen before the app is fully launched. You can define it in your fly.toml file under the [deploy] section.

Example:


[deploy]
  release_command = "python manage.py migrate"


This ensures your migrations or other essential pre-deploy tasks run seamlessly during the deployment process!

#fly #db_migrations
adithya.hebbar
Adithya Hebbar
System Analyst
Oct 7, 2024
useFieldArray is a hook provided by React Hook Form that simplifies the process of managing dynamic form fields. It allows you to create forms where users can add, remove, move, and manipulate groups of inputs (or arrays of fields), like a list of tasks, addresses, or any repeatable form sections.
Features :-
1. Dynamic Fields Management
2. Efficient Rendering
Functions Provided by useFieldArray
append(): Adds a new item to the end of the field array.
prepend(): Adds a new item to the beginning of the field array.
remove(index): Removes a field at the specified index.
insert(index, value): Inserts a new field at a specific index.
#react-hook #react-form #form
ayasha.pandey
Ayasha Pandey
System Analyst
Oct 7, 2024
To create a model in Prisma:
1. Open the schema.prisma file.
2. Define datasource and generator:


datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider = "prisma-client-js"
}


Create the model:


model Retro {
  id              String   @id @default(cuid())
  date            DateTime @default(now())   // Auto-fills current date
  scrumMasterId   String                        // For Scrum Master (User)
  slackChannel    String                        // Slack Channel input
  questions       String[]                      // Default retro questions
  projectId       Int       @relation(fields: [projectId], references: [id])
  project         Project   @relation(fields: [projectId], references: [id])
}


This creates the Retro table for your retrospectives.

@id: Marks a field as the primary key.
@default(): Sets a default value for a field.
@relation(): Defines relationships between models.
@unique: Ensures a field has unique values.
String[]: Defines an array of strings.
cuid(): Generates a unique ID.
@updatedAt: Automatically updates the field with the current timestamp when data changes.

#prisma #database #columns #model
amber.srivastava
amber.srivastava

Showing 11 to 13 of 79 results

Ready to Build Something Amazing?

Codemancers can bring your vision to life and help you achieve your goals