Creating ID8-9

parent 71b84103
class JobFavoritesController < ApplicationController
before_action :sign_in_validation, only: [:create, :destroy]
before_action :find_job_id, only: [:new]
def create
end
def destroy
end
private
def sign_in_validation
return if signed_in?
store_location
flash[:warning] = Settings.user.warning_signin
redirect_to login_path
end
end
......@@ -3,7 +3,7 @@ class User < ApplicationRecord
before_create :create_remember_token
mount_uploader :cv_user, UserCvUploader
has_many :favorite_jobs
has_many :favorite_jobs, foreign_key: "job_id", dependent: :destroy
has_many :jobs, through: :favorite_jobs
has_many :job_applieds
has_many :jobs, through: :job_applieds
......@@ -20,6 +20,18 @@ class User < ApplicationRecord
PASSWORD_FORMAT = /\A(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])/x
validates :password, format: { with: PASSWORD_FORMAT, message: "is too short or not strength" }
def following?(job_id)
favorite_jobs.find_by(job_id: job_id)
end
def follow!(job_id)
favorite_jobs.create!(job_id: job_id)
end
def unfollow!(job_id)
favorite_jobs.find_by(job_id: job_id).destroy
end
def self.new_remember_token
SecureRandom.urlsafe_base64
end
......
......@@ -17,7 +17,9 @@
<%= link_to 'Read more..', job_detail_path(job.id) %>
</div>
</div>
<%= link_to follow_job_path(job.id) do %>
<button type="button" class="btn btn-primary" id="button-follow">♥ Follow</button>
<% end %>
</div>
</div>
<br>
......
......@@ -33,6 +33,9 @@ Rails.application.routes.draw do
get 'jobs/industry/:converted_name', to: 'jobs#industry_jobs', as: :industry_jobs
get 'jobs/company/:converted_name', to: 'jobs#company_jobs', as: :company_jobs
post 'follow_job', to: 'job_favorites#create', as: :follow_job
resources :job_favorites, only: [:create, :destroy]
resources :job_applieds,only: [:new, :create]
resources :reset_passwords, only: [:edit, :update]
resources :confirmations, only: [:new]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment