Search
 
SCRIPT & CODE EXAMPLE
 

RUBY

rails generate model

rails generate model Article title:string body:text


[Output]

invoke  active_record
create    db/migrate/<timestamp>_create_articles.rb
create    app/models/article.rb
invoke    test_unit
create      test/models/article_test.rb
create      test/fixtures/articles.yml
Comment

rails generate model with options

class Article < ApplicationRecord
  has_many :comments

  validates :title, presence: true
  validates :body, presence: true, length: { minimum: 10 }

  VALID_STATUSES = ['public', 'private', 'archived']

  validates :status, inclusion: { in: VALID_STATUSES }

  def archived?
    status == 'archived'
  end
end
Comment

PREVIOUS NEXT
Code Example
Ruby :: ! in ruby 
Ruby :: ruby generate array of numbers 
Ruby :: user.destroy all except one rails 
Ruby :: how to add variable inside string ruby 
Ruby :: sentry send error manually ruby 
Ruby :: ros2 publish message command line 
Ruby :: ruby to_a 
Ruby :: ruby prepend string 
Ruby :: ruby new class params 
Ruby :: rails faker address 
Ruby :: rails check test database 
Ruby :: rails select arbitrary n element from array 
Ruby :: ruby create object with attributes 
Ruby :: dependent destroy, only the foreign key 
Ruby :: how to comment out embedded ruby 
Ruby :: elsif ruby 
Ruby :: how to run one line pry 
Ruby :: ruby-on-rails 
R :: automatically wrap r text label ggplot 
R :: how to append in R list 
R :: r return index of rows that have NA in dataframe 
R :: create dataframe or table in r 
R :: how to return the date with only the day in it in r 
R :: ggplot2 black and white theme 
R :: ggplot2 legend text 
R :: find row with na r 
R :: R vector all but last 
R :: how to format a number in r 
R :: ggplot glm 
R :: not equals r 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =