menu
With this command, you can check the commit logs in another branch of your project. It's very useful when other coworkers push changes to the main branch.

case main branch: git log -g main
git stash show -p stash@{0}
When coding across multiple tabs and needing to split your screen to work on another file, use this command:

ctrl/cmd + \

In certain instances, when sharing content via Rails view using I18n and incorporating specific HTML instructions, such as the requirement to set a string in bold, we follow this approach:

# config/locales/en.yml
en:
  homepage:
    services:
      title: "This is the <strong>example</strong>"

in this case should use the html_safe method in views like:

 <h1><%= t(:title, scope: %w[homepage services]).html_safe %></h1>

with this implementation, any HTML tag can work effectively.
Is possible to navigate over tabs in a custom panel with this shortcut:

ctrl/cmd + shift + a 
The :back symbol in Rails is often used to generate a URL that represents the previous page or location the user came from. It's commonly utilized in conjunction with methods like redirect_to redirecting users back to where they were before performing a specific action.


Here's a brief explanation:

- Usage with redirect_to you can use :back with the redirect_to method to send the user back to the previous page:

redirect_to :back

Usage with Links, You can also use :back as the path in a link to create a "Back" button or link:

<%= link_to 'Back', :back, class: 'btn btn-primary' %> 

Switch your rails app database without having to touch a single file. Pass --force to skip prompts.

rails db:system:change --to=postgresql
Ruby's Enumerable#cycle offers an easy way to either repeat a certain pattern n times or just to switch between two predefined states. 

Repeating a certain pattern:

irb> array = [1, 2, 3]  
=> [1, 2, 3] 
irb> array.cycle(3).to_a  
=> [1, 2, 3, 1, 2, 3, 1, 2, 3] 

Switching between two states:

irb> button = ['on', 'off'].cycle  
=> # 
irb> button.next  
=> "on" 
irb> button.next  
=> "off" 


In your session, it's necessary to set the editor for opening files using this export command:

export EDITOR= 

Afterward, to open the gem files, use the following command:
 
bundle open

This action allows you to open any gem within your Rails project, enabling you to explore its internals and understand the current flow, helping you solve any issues related to it.


In rails 7 the correct way to render templates through the wicked_pdf gem is:

template: 'folder/file', formats: [:html]

is important to know that now is required to set the file without the file extension.
The :not pseudo selector is useful for styling a group of elements while leaving the last (or specified) element unstyled.

 
HTML
One
Two
Three
Four


CSS
.css-not-selector-shortcut { 
 display: flex; 
}

ul { padding-left: 0; }
li { list-style-type: none; margin: 0; padding: 0 0.75rem; }
li:not(:last-child) { border-right: 2px solid #d2d5e4; }

y - stage this hunk

n - do not stage this hunk

q - quit; do not stage this hunk or any of the remaining ones

a - stage this hunk and all later hunks in the file

d - do not stage this hunk or any of the later hunks in the file

g - select a hunk to go to

/ - search for a hunk matching the given regex

j - leave this hunk undecided, see next undecided hunk

J - leave this hunk undecided, see next hunk

k - leave this hunk undecided, see previous undecided hunk

K - leave this hunk undecided, see previous hunk

s - split the current hunk into smaller hunks

e - manually edit the current hunk

? - print help

By default, Rails ships with three environments: "development," "test," and "production." To navigate between each environment, you can use the following command: 
 
 
bin/rails db:environment:set RAILS_ENV="YOUR_ENVIRONMENT" 
If you are using the devise gem the initial redirection will be to '/' even though you have another enable route '/welcome'.
So the solution can be achieved with this: 

  • app/controllers/application_controller.rb:

def after_sign_in_path_for(resource) 
 welcome_path 
end 
The Heroku CLI offers numerous benefits, including the ability to directly check how many apps are in your account using this command:
heroku apps

If you want to verify the most critical information about a specific app, you can use this command: 
heroku apps:info --app example

FYI is important that you log login before.