Thursday, March 28, 2024
HomeRuby On RailsRuby on Rails Ideas and Tips

Ruby on Rails Ideas and Tips


# Rails Console
app
helper.number_to_currency(10)
helper.number_to_percentage(42, precision: 2)

Consumer.the place(created_at: 10.days.in the past..Time.now)
# IRB Console
sort_options = [:id, :title, :author]
# kind = sort_options.embody?(params[:sort]) ? params[:sort] : :id
# kind = (sort_options.embody?(params[:sort]) && params[:sort]) || :id
kind = params[:sort].presence_in(sort_options) || :id

1 <=> 2 # => -1
10 <=> 2 # => 1
10 <=> 10 # => 0

cash = 9.5
"%.2f" % cash # => "9.50"

%w{a b} # => ["a", "b"]
%i{a b} # => [:a, :b]

12 months = 1972
case 12 months
when 1970..1979: "Seventies"
when 1980..1989: "Eighties"
when 1990..1999: "Nineties"
finish
# Terminal
rails g mannequin remark consumer:belongs_to physique:textual content -p

rails log:clear

tail -f log/growth.log | grep DEBUG

echo 'gem: --no-document' >> ~/.gemrc

EDITOR=code bundle open <GEMNAME>
EDITOR=code gem open <GEMNAME>

bundle outdated
# fashions/profile.rb
class Profile < ApplicationRecord
  belongs_to :consumer

  delegate :electronic mail, to: :consumer
  # def electronic mail
  #   consumer.electronic mail
  # finish
finish

# profile.electronic mail
# ~/.railsrc
--skip-spring
--no-helper
--no-assets
--no-controller-specs
--no-view-specs
# application_controller.rb
class ApplicationController < ActionController::Base
  def user_signed_in?
    # !current_user.nil?
    !!current_user
  finish
finish
# Terminal
yarn add stimulus
# app/javascript/packs/software.js
import 'controllers'
# app/javascript/controllers/index.js
import { Software } from "stimulus"
import { definitionsFromContext } from "stimulus/webpack-helpers"

const software = Software.begin()
const context = require.context("controllers", true, /.js$/)
software.load(definitionsFromContext(context))
# app/javascript/controllers/whats up/world_controller.js
import { Controller } from "stimulus"

export default class extends Controller {
  initialize(){
    console.log("HELLO WORLD")
  }
}
# View
<div data-controller="whats up--worlds">
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments