Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUBY

Ruby on Rails

#Start App
rails new blog
# Create pages
rails g controller pages home about
# Open console
rails c

#Create table
rails g scaffold post title body:text

#Migrate table
rails db:migrate

#To create a new post through the console
rails c
Post.new
@post = Post.new(title: "Tristan", body: "My baby is crying")
@post.save

OR
Post.create(title:"Annita Kerubo", body: "The mother of my child")

#Grab post
@post = Post.find(2)
@post.title

#Get last two posts
@post = Post.last(2)

#Create dev data

10.times do |x|
  Post.create(title: "Title #{x}", body: "body #{x} words go here")
end
rails db:seed

#Create views
rails g migration add_views_to_posts views:integer
rails db:migrate

#Add user setups using devise gem

Add the following line to your Gemfile:
gem 'devise'

bundle install
rails generate devise:install
rails g devise User
rails db:migrate

#To check available routes
rails routes







 
PREVIOUS NEXT
Tagged: #Ruby #Rails
ADD COMMENT
Topic
Name
9+3 =