Skip to content

macodingclub/Bartevian

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Generate connected DB and Model from the command line

rails g model Book title:string description:text author: string price:integer

Book's Model is singular(book) and in the db is plural(books)

Create database from migration file

rake db:migrate

Start server

rails s

Generate controller from the command line

rails g controller Books

Check routes for the app

rake routes

In routes.rb file , create a restful route

resources :books

In routes.rb file defining the root of the application

root ‘books#index’

Install the gems, every time needs to be run when we installing new gems

bundle install

Install simple_form gems with incorporated bootstrap

rails g simple_form:install –bootstrap

Install gem devise for login, logout

gem 'devise', '~> 4.2'

rails g devise:install

rails g devise:views

rails g devise User

Update DB with the new USER tables

rake db:migrate

Create relashions between user_id and items

rails g migration add_user_id_to_items user_id:integer

Connect with the DB through the console. Item is the DB-table

rails c

Item.connection

Item – see all fields and types of fields

Item.first | Item.last | Item.find(3) – find by id

Create variables with results from the DB query

rails c

Item.connection

@book = Item.last

@item.user_id = 1

@item.save

In show.html.erb- Add the logic if the user is login

<% if user_signed_in? %>

<% if @item.user_id == current_user.id %>

<%= link_to “Edit”, edit_item_path(@item) %>

<%= link_to “Delete”, item_path(@item), method: :delete, data: { confirm: “Are you sure” } %>

<% end %>

<% end %>

Connect with the DB through the console and add Categories manually

rails c

Category.connection

Category.create(name: “Art”)

Write pure SQL to the DB

rails db

.tables

README

This README would normally document whatever steps are necessary to get the application up and running.

Things you may want to cover:

  • Ruby version

  • System dependencies

  • Configuration

  • Database creation

  • Database initialization

  • How to run the test suite

  • Services (job queues, cache servers, search engines, etc.)

  • Deployment instructions

  • ...

PostgreSQL local configuration:

=========================================== sudo apt-get install postgresql export DATABASE_URL=postgres:///$(whoami) sudo -u postgres createuser -s $(whoami); createdb $(whoami) bundle install

=========================================== to completely remove postgreSQL: ps -C postgres ...if shows processes, then: sudo killall postgres ps -C postgres …if there are no mo running processes, then:

sudo apt-get --purge remove postgresql* sudo rm -r /etc/postgresql/ sudo rm -r /etc/postgresql-common/ sudo rm -r /var/lib/postgresql/ udo userdel -r postgres sudo groupdel postgres

===========================================