Rake, migration, pry with pow, adding AR validations to plain Ruby objects
lib/tasks/name.rake
(if one doesn't already exist)task :hello do
# code you want to execute with this task
end
task :name_of_task
+ a do/end blocktask :hello do
puts "Hello from rake"
end
rake hello
rake -T
to see view a list BUT in order for this to work,
we need to give our tasks descriptionsdesc 'Outputs hello to the terminal'
task :hello do
puts "hello from rake"
end
namspace :greeting do
desc 'Outputs hello to the terminal'
task :hello do
puts "Hello from the terminal"
end
desc 'Ouputs goodbye to the terminal'
task :goodbye do
puts "Goodbye from the terminal"
end
end
rake greeting:hello
rake greeting:goodbye
namespace :db do
desc 'migrates changes to your database'
task :migrate => :environment do
Student.create_table
end
end
task :migrate => :environment
Student.create_table
would require access to the
config/environment.rb file (which is where the student class and database are loaded)task :environment do
require_relative './config/environment'
end
gem install pg
rails new myapp --database=postgres
You can configure which database Rails will talk to, this is done using the database.yml file,
which is located at config/database.yml
the database.yml file is used by Rails to connect to the appropriate database
YAML = data serialization standard
Rails convention for the username is the name of the app
the password should match the password of the user from step 2
Next add the following to each environment (ex development) in the database.yml file:
development:
adapter: postgresql
encoding: unicode
database: nameofapp_development
username:
password:
rake db:setup
default: &default
adapter: postgresql
encoding: unicode
pool: 5
username: parms
password:
timeout: 5000
development:
<<: *default
rails generate <name of generator> name_of_generator <options> --no-test-framework
-- OR
rails g <name of generator> nameOfGenerator<options> --no-test-framework
rails destroy <name of generator> name #undo rails g
-- OR
rails d <name of generator> name
-- To generate a resource within a namespace:
rails g resource namespace_name/name_of_resource
rails g resource name fields --no-test-framework
rails g model name_of_model table_column_name:type
rails g model ServiceLocations address:string
rails g migration AddColumnNameToTable col1:type col2:type ...
rails g migration RemoveColumnNameFromTable colName
rake db:rollback
t.datatype :name
gem 'pry-remote', :group => :development
bundle install
binding.remote_pry
pry-remote
include ActiveModel::Validations
.ruby-gemset
and .ruby-version