Chapter 3. Creating custom website for hire workers

Chapter 3. Creating custom website for hire workers

Bravo webdev

Hi there. This is 3th chapter of our tutorial "Creating custom website for hire workers". 

previous chapters available at out telegram channel ang group.

https://t.me/bravowebdevchannel

https://t.me/bravowebdev


Today we need add registration to our website. Also we will create resources: Headhunter, Worker, Admin, Job, Application, Tag.

Headhunter, Admin, Worker has same things:

user when register can choose type of profile (Hedhubter or worker). Admins registration page is not shown at main page.

Name, Contact.

HeadHunter, Admin, Worker inherited from User model and they are separeate models (idk why)

Job is absoluty different resource. The job model has own controller. Job model has title, description, tags, workers_count,headdunter_id. Status (active, unactive)

Application is resource that represents dialog between headhunter and worker. Application has worker_id (who create this application), job_id, statuses (opened,hr_approved,closed), work_done_approval (hr_approval, worker_approval).

Admin profile page has all jobs, workers, hedhunters list. Also he see applications and can search with filters (headhunter, worker name, id, datatime, statuses). He can change job status from active to inactive and this process is logged. Also he can block worker and headhunter and this is blocked. He can see in worker or hedhubter profile how many times they are blocked and how much time this block durates.

The controller of Job. Standart crud. But when headhunter create job, his id saved at job. Also before crud hedahubters profile checked blocked or not.

The admins controller allow him see headhunters, workers and block them. Also he can see and search applications. When he block someone, the user blocked status from false to true and to Admin Blocks log new row. status-blocked, Blocked_account, datetime, reason. And if he unblock someone also status-unblocked, unblocked account, datetime, reason.

The headhunter controoler allow him edit own profile - name and contact, password, email.

The workers controller allow him edit his profile - name and contact, password, email.

The application controller crud application and change statuses with checking permissions. 

The job controller also change statuss with permission controllers.

We need templates for our website:

profile_template: worker,headhunter, admin

job_template

main template for registration

page for registration for admins


Lets starts with creating models for our resources and routes. HeadHunter, User and Admin must have registration ang login option. For this we will use gem 'devise'

Open Gemfile, type gem 'devise'

bundle install

rails generate devise:install


Add to config/environments/development.rb:


config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }


 Ensure you have flash messages in app/views/layouts/application.html.erb.

   For example:


    <p class="notice"><%= notice %></p>

    <p class="alert"><%= alert %></p>


type rails g devise:views


type rails generate devise headhunter

rails g devise worker

rails g devise admin


open db/migrate migrations 20***20_devise_create_headhunter etc

and add 

   t.string :name

   t.string :contact

to headhunter, worker and admin migration

then type

rails db:migrate


lets make registration (devise) templates or views for our app.

rails generate devise:views headhunters

rails g devise:views admins

rails g devise:views workers


Okay we have pages for registration and sign in. But if im a gues what page I see first? Rails logo, I as a guest dont know about registration pages for headhunters,workers, admins (for admins ok, its good, that nobody know theie root page). But for registration as headhunter or admin we need a main page. Also we put to this page short description about our website. Lets create it.


rails g controller Jobs

Open app/views/jobs and create new file 'index.html.erb'

Add to new file

<p>This is an article from index.html.erb </p>

add to the config/routes.rb

root to: "jobs#index"


rails g resource Job


open create_job migration from db/migrate


   t.string :title

   t.string :description

   t.integer :workers_count

   t.integer :status

   t.belongs_to :headhunter

Open Job from app/model add

belongs_to :headhunter

enum status: [:active, :inactive]

Open headhunter from app/model and add

has_many :jobs  


then type

rails db:migrate


and check it. rails s 

you will see our message "This article from index.html.erb"


Now we need to create headhunter and worker profile pages to redirect after login. And add login/regisration links at our jobs/index template for all guests. After this we will add more data to registration devise default page for headhunter and worker - name and contact

create app/views/headhunters/index.html.erb


create app/views/workers/index.html.erb


open app/views/jobs/index.html.erb


<p> link_to "Registration as headhunter", new_headhunter_registration </p>

<p>link_to "Login as headhunter", new_headhunter_session</p>

<br/>

<p>link_to "Registration as worker", new_worker_registration </p>

<p> link_to "Login as worker", new_worker_session </p>


type

rails g controller headhunters

rails g controller workers


open them and edit. same for workers

def index

end

def show

@Headhunter = Headhunter.find(params[:id])

end


add to config/routes.rb

 resources :headhunters

 resources :workers


You can check registration

rails s and registration works, but you return back at jobs index. In next chapter we will add redirection to profile (headhunter to headhunter profile, worker to worker profile).


Join us

t.me/bravowebdevchannel

t.me/bravowebdev


Report Page