Sf-60-Ruby-Cisco / BE-Ruby-Project

0 stars 0 forks source link

Create Project Skeleton #5

Closed apoltieva closed 2 years ago

apoltieva commented 2 years ago

We are yet to agree on data model for our application but that doesn't block us on creating the initial skeleton for the project.

ACs (acceptance criteria):

Stoyan83 commented 2 years ago

Ubuntu tutorial

We create first new rails app with postgre database and without Test::Unit because we'll use rspec

rails car_diary -d postgresql -T

-T option tells rails not to include Test::Unit

-d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/postgresql/sqlite3... and so on


Rails create an empty database for you

rake db:create

Installing rspec


Add in Gemfile

gem 'rspec-rails'

From the command line install the gem

bundle install

From the command line install rspec into your application:

rails g rspec:install


Swap template engine from ERB to slim

Add in gem file:

gem 'slim-rails'

From the command line install the gem

bundle install

In config/application.rb add this line of code

class Application < Rails::Application

    config.generators do |g|
      g.template_engine :slim
    end
end

Convert to Slim in one hit.

Firstly install the following gems:

gem install html2haml haml2slim

Run the following in the terminal to convert ERB to Slim in place (it creates a Slim file and removes the old ERB file):

find ./app/views -name '*.erb' | xargs -I file sh -c \
'html2haml --erb file | haml2slim > $(echo file | sed 's/erb/slim/') && \
rm file'

Create a simple controller and a view to check if it is working on port 3000

rails generate controller home index

Run the server:

rails s