create store_location

parent ca4676d4
Pipeline #1023 canceled with stages
in 0 seconds
...@@ -3,6 +3,8 @@ class JobAppliedsController < ApplicationController ...@@ -3,6 +3,8 @@ class JobAppliedsController < ApplicationController
before_action :find_job_id, only: [:new] before_action :find_job_id, only: [:new]
def new def new
founded_application = JobApplied.where(user_id: current_user.id, job_id: params[:job_id])
return redirect_to job_detail_path(params[:job_id]) if founded_application.present?
end end
def show def show
...@@ -35,7 +37,8 @@ class JobAppliedsController < ApplicationController ...@@ -35,7 +37,8 @@ class JobAppliedsController < ApplicationController
def sign_in_validation def sign_in_validation
return if signed_in? return if signed_in?
flash[:warning] = "Please Sign In..." store_location
flash[:warning] = Settings.user.warning_signin
redirect_to login_path redirect_to login_path
end end
......
...@@ -27,7 +27,8 @@ class JobsController < ApplicationController ...@@ -27,7 +27,8 @@ class JobsController < ApplicationController
end end
def show def show
redirect_to jobs_path unless @job return redirect_to jobs_path unless @job
@user = JobApplied.where(user_id: current_user.id, job_id: params[:id]) if signed_in?
end end
private private
......
...@@ -8,7 +8,7 @@ class SessionsController < ApplicationController ...@@ -8,7 +8,7 @@ class SessionsController < ApplicationController
user = User.find_by(email: params[:session][:email].downcase) user = User.find_by(email: params[:session][:email].downcase)
if user && user.authenticate(params[:session][:password]) if user && user.authenticate(params[:session][:password])
sign_in user sign_in user
redirect_to my_page_path redirect_back_or my_page_path
else else
flash.now[:danger] = Settings.user.sign_in.failed flash.now[:danger] = Settings.user.sign_in.failed
render 'new' render 'new'
......
...@@ -40,6 +40,7 @@ class UsersController < ApplicationController ...@@ -40,6 +40,7 @@ class UsersController < ApplicationController
def sign_in_validation def sign_in_validation
return if signed_in? return if signed_in?
store_location
flash[:warning] = Settings.user.warning_signin flash[:warning] = Settings.user.warning_signin
redirect_to login_path redirect_to login_path
end end
......
...@@ -27,4 +27,12 @@ module SessionsHelper ...@@ -27,4 +27,12 @@ module SessionsHelper
self.current_user = nil self.current_user = nil
end end
def redirect_back_or(default)
redirect_to(session[:return_to] || default)
session.delete(:return_to)
end
def store_location
session[:return_to] = request.url if request.get?
end
end end
...@@ -18,10 +18,16 @@ ...@@ -18,10 +18,16 @@
<% end %>/&ensp; <% end %>/&ensp;
<%= @job.title.truncate_words(5) %> <%= @job.title.truncate_words(5) %>
</div> </div>
<%= link_to apply_job_path(job_id: @job.id) do %> <% if signed_in? && @user.present? %>
<div class="apply-job"> <div class="apply-job">
<strong>Apply Now</strong> <strong>Applied</strong>
</div> </div>
<% else %>
<%= link_to apply_job_path(job_id: @job.id) do %>
<div class="apply-job">
<strong>Apply Now</strong>
</div>
<% end %>
<% end %> <% end %>
</div> </div>
</div> </div>
...@@ -68,10 +74,16 @@ ...@@ -68,10 +74,16 @@
</div> </div>
<div class="row under-descrip"> <div class="row under-descrip">
<div class="col-6"> <div class="col-6">
<%= link_to apply_job_path(job_id: @job.id) do %> <% if signed_in? && @user.present? %>
<div class="btn btn-info btn-lg apply-btn"> <div class="btn btn-info btn-lg apply-btn">
<strong>Apply Now</strong> <strong>Applied</strong>
</div> </div>
<% else %>
<%= link_to apply_job_path(job_id: @job.id) do %>
<div class="btn btn-info btn-lg apply-btn">
<strong>Apply Now</strong>
</div>
<% end %>
<% end %> <% end %>
</div> </div>
<div class="col-6"> <div class="col-6">
......
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