Monday, November 28, 2022
HomeRuby On RailsRuby on Rails Ideas and Methods

Ruby on Rails Ideas and Methods


# 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.embrace?(params[:sort]) ? params[:sort] : :id
# kind = (sort_options.embrace?(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]

yr = 1972
case yr
when 1970..1979: "Seventies"
when 1980..1989: "Eighties"
when 1990..1999: "Nineties"
finish
# Terminal
rails g mannequin remark person: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 :person

  delegate :electronic mail, to: :person
  # def electronic mail
  #   person.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/utility.js
import 'controllers'
# app/javascript/controllers/index.js
import { Utility } from "stimulus"
import { definitionsFromContext } from "stimulus/webpack-helpers"

const utility = Utility.begin()
const context = require.context("controllers", true, /.js$/)
utility.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