Sinatra-Travels App

Ludmila Korchnoy
2 min readApr 12, 2020

The name of my project-mvc is Sinatra-Travels app. I used Corneal gem which set up folders automatically. First, I looked at my Gemfile requiring gems, run ‘bundle install’ to create Gemfile.lock. I went through my Rakefile, I required ‘./config/environment’ and ‘sinatra/activerecord/rake’ also set up pry. In config.ru I set up controllers and use Rack::MethodOverride. In my environment I set up connection to my database and required all of the files, and in config.ru I required environment. “The ActiveRecord gem gives us access to the magical database mapping and association powers”. Rake gem “automates tasks such as database creation”(Learn.co). I ran the command ‘rake db:create_migration NAME=create_users’ in the terminal and created a file inside of db/migrate folder, in order to create database table. In my class CreateUsers table ‘:users’ has attributes: username, email, password_digest (encrypted password from ‘bcrypt gem’). All of the attributes from the table users will create an instance of the User class. class CreateUsers < ActiveRecord::Migration def change create_table :users do |t| t.string :username t.string :email t.string :password_digest end end end

The same way I created my other tables. By running the command ‘rake db:migrate’ created my tables in schema.rb. I created classes in my models folder and set up the relationships association. I created routes in my controller classes implementing CRUD and connected controller actions to views by rendering erb pages. Also, created helpers class. When I created a form in the views/users file: ‘signup form’, I used the attributes from the users table: username, email and password. When input names match column names in the table ‘

each time a new user is being created user = User.create(params) params hash automatically included the key-value data of username, email, password. Equivalent to user = User.create(username: params[:username], email: params[:email], password: params[:password]) Running pry, and entering ‘user = User.create(params)’ gives me all of the information:

#<User:0x00007f976b2d8a98 id: 9, username: “Alexandra”, email: “alexandra@alexandra.com”, password_digest: “$2a$12$.bkAblYYtQMC4t4ynZKaXexzblgI9/S0Neim.m.oi1XvLoGvnlKcu”>

Went the program was running smoothly, I uploaded the image I would be using for my app into public/images folder and used css to style my app and center the image. It was fun, interesting and educational experience. Awesome to see the project that I created in action and functioning, and could be used by other folks.

Originally published at https://lkorchnoy.github.io on April 12, 2020.

--

--

Ludmila Korchnoy

Hello World! I’m a Full stack web developer experienced in Ruby and JavaScript frameworks. I graduated Flatiron School in October of 2020.