Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
venjobs_app
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Quang Vinh Nguyen
venjobs_app
Commits
13c666b9
Commit
13c666b9
authored
Jun 25, 2018
by
Quang Vinh Nguyen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix almost error from review
parent
70f021b1
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
49 additions
and
85 deletions
+49
-85
app/controllers/entries_controller.rb
+20
-31
app/models/job.rb
+0
-2
app/models/user.rb
+5
-4
app/views/devise/registrations/edit.html.erb
+3
-1
app/views/entries/_entry.json.jbuilder
+0
-2
app/views/entries/_form.html.erb
+8
-2
app/views/entries/index.html.erb
+0
-29
app/views/entries/index.json.jbuilder
+0
-1
app/views/jobs/show.html.erb
+3
-9
app/views/user_mailer/job_apply.html.erb
+1
-1
app/views/user_mailer/job_apply.text.erb
+1
-1
config/routes.rb
+1
-1
db/migrate/20180607084045_devise_create_users.rb
+2
-1
db/migrate/20180612070531_create_entries.rb
+2
-0
db/schema.rb
+3
-0
No files found.
app/controllers/entries_controller.rb
View file @
13c666b9
# frozen_string_literal: true
class
EntriesController
<
ApplicationController
before_action
:set_entry
,
only:
[
:show
,
:edit
,
:update
,
:destroy
]
# GET /entries
# GET /entries.json
def
index
@entries
=
Entry
.
all
end
before_action
:set_entry
,
only:
[
:show
,
:edit
,
:update
]
before_action
:entry_params
,
only:
[
:create
]
# GET /entries/1
# GET /entries/1.json
...
...
@@ -15,16 +10,16 @@ class EntriesController < ApplicationController
# GET /entries/new
def
new
if
params
[
:entry_name
].
blank?
&&
params
[
:entry_email
]
@entry
=
Entry
.
new
else
@entry
=
Entry
.
new
(
entry_name:
params
[
:entry_name
],
entry_email:
params
[
:entry_email
])
end
@entry
=
if
user_signed_in?
Entry
.
new
(
entry_name:
current_user
.
name
,
entry_email:
current_user
.
email
,
entry_phone:
current_user
.
phone
,
entry_address:
current_user
.
address
)
else
Entry
.
new
end
end
# GET /entries/1/edit
def
edit
;
end
# POST /entries
# POST /entries.json
def
create
...
...
@@ -32,19 +27,20 @@ class EntriesController < ApplicationController
@job
=
Job
.
find
(
params
[
:job_id
])
@user
=
User
.
find_by
(
email:
params
[
:entry
][
:entry_email
])
||
User
.
create
(
name:
params
[
:entry
][
:entry_name
],
email:
params
[
:entry
][
:entry_email
],
password:
'password'
,
password_confirmation:
'password'
)
@user
=
User
.
find_by
(
email:
params
[
:entry
][
:entry_email
])
||
User
.
create
(
name:
params
[
:entry
][
:entry_name
],
email:
params
[
:entry
][
:entry_email
],
phone:
params
[
:entry
][
:entry_phone
],
address:
params
[
:entry
][
:entry_address
])
#,
# password: 'password',
# password_confirmation: 'password')
@entry
.
user_id
=
@user
.
id
@entry
.
job_id
=
@job
.
id
if
@user
.
jobs
.
include?
(
@job
)
# redirect_to job_url(@job), notice: 'You has been entry this job.'
if
@user
.
jobs
.
find_by
(
id:
@job
.
id
)
redirect_to
job_url
(
@job
),
flash:
{
secondary:
'You has been entry this job.'
}
els
if
els
e
if
@entry
.
save
UserMailer
.
job_apply
(
@user
,
@job
).
deliver_now
redirect_to
@entry
,
flash:
{
secondary:
'Thank you for apply. Please check your email.'
}
...
...
@@ -64,13 +60,6 @@ class EntriesController < ApplicationController
end
end
# DELETE /entries/1
# DELETE /entries/1.json
def
destroy
@entry
.
destroy
redirect_to
entries_url
,
notice:
'Entry was successfully destroyed.'
end
private
# Use callbacks to share common setup or constraints between actions.
...
...
@@ -80,6 +69,6 @@ class EntriesController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def
entry_params
params
.
require
(
:entry
).
permit
(
:entry_name
,
:entry_email
)
params
.
require
(
:entry
).
permit
(
:entry_name
,
:entry_email
,
:entry_phone
,
:entry_address
)
end
end
app/models/job.rb
View file @
13c666b9
...
...
@@ -15,8 +15,6 @@ class Job < ApplicationRecord
dependent: :destroy
has_many
:users
,
through: :entries
has_many
:entries
,
dependent: :destroy
has_many
:favorite_jobs
,
dependent: :destroy
validates
:title
,
presence:
true
,
length:
{
maximum:
255
},
uniqueness:
{
case_sensitive:
false
}
...
...
app/models/user.rb
View file @
13c666b9
# frozen_string_literal: true
class
User
<
ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise
:database_authenticatable
,
:registerable
,
:recoverable
,
:rememberable
,
:validatable
,
:confirmable
:recoverable
,
:rememberable
,
:validatable
#
,
#
:confirmable
has_many
:entries
,
dependent: :destroy
has_many
:favorite_jobs
,
dependent: :destroy
has_many
:favorite_jobs
,
dependent: :destroy
has_many
:entries
,
foreign_key:
'user_id'
,
dependent: :destroy
...
...
app/views/devise/registrations/edit.html.erb
View file @
13c666b9
...
...
@@ -35,9 +35,10 @@
<%=
f
.
submit
"Update"
%>
</div>
<%
end
%>
<!--
<h3>Cancel my account</h3>
<p>Unhappy?
<%=
button_to
"Cancel my account"
,
registration_path
(
resource_name
),
data:
{
confirm:
"Are you sure?"
},
method: :delete
%>
</p>
<%=
link_to
"Back"
,
:back
%>
-->
\ No newline at end of file
app/views/entries/_entry.json.jbuilder
deleted
100644 → 0
View file @
70f021b1
json.extract! entry, :id, :entry_name, :entry_email, :created_at, :updated_at
json.url entry_url(entry, format: :json)
app/views/entries/_form.html.erb
View file @
13c666b9
...
...
@@ -14,10 +14,16 @@
<%=
hidden_field_tag
:job_id
,
@job
.
id
%>
<%=
form
.
label
:name
%>
<br>
<%=
form
.
text_field
:entry_name
,
class:
'form-control col-sm-
4
'
%>
<br>
<%=
form
.
text_field
:entry_name
,
class:
'form-control col-sm-
6
'
%>
<br>
<%=
form
.
label
:email
%>
<br>
<%=
form
.
email_field
:entry_email
,
class:
'form-control col-sm-4'
%>
<br>
<%=
form
.
email_field
:entry_email
,
class:
'form-control col-sm-6'
%>
<br>
<%=
form
.
label
:phone
%>
<br>
<%=
form
.
telephone_field
:entry_phone
,
class:
'form-control col-sm-6'
%>
<br>
<%=
form
.
label
:address
%>
<br>
<%=
form
.
text_area
:entry_address
,
class:
'form-control col-sm-6'
%>
<br>
<%=
form
.
submit
yield
(
:button_text
),
class:
"btn btn-secondary"
%>
<%=
link_to
'Back'
,
:back
,
class:
"btn btn-secondary"
%>
...
...
app/views/entries/index.html.erb
deleted
100644 → 0
View file @
70f021b1
<p
id=
"notice"
>
<%=
notice
%>
</p>
<h1>
Entries
</h1>
<table>
<thead>
<tr>
<th>
Entry name
</th>
<th>
Entry email
</th>
<th
colspan=
"3"
></th>
</tr>
</thead>
<tbody>
<%
@entries
.
each
do
|
entry
|
%>
<tr>
<td>
<%=
entry
.
entry_name
%>
</td>
<td>
<%=
entry
.
entry_email
%>
</td>
<td>
<%=
link_to
'Show'
,
entry
%>
</td>
<td>
<%=
link_to
'Edit'
,
edit_entry_path
(
entry
)
%>
</td>
<td>
<%=
link_to
'Destroy'
,
entry
,
method: :delete
,
data:
{
confirm:
'Are you sure?'
}
%>
</td>
</tr>
<%
end
%>
</tbody>
</table>
<br>
<%=
link_to
'New Entry'
,
new_entry_path
%>
app/views/entries/index.json.jbuilder
deleted
100644 → 0
View file @
70f021b1
json.array! @entries, partial: 'entries/entry', as: :entry
app/views/jobs/show.html.erb
View file @
13c666b9
...
...
@@ -11,16 +11,10 @@
<%=
@job
.
description
%>
</p>
<%
if
user_signed_in?
%>
<%=
link_to
"Apply"
,
{
controller:
"entries"
,
action:
"new"
,
job_id:
@job
.
id
,
entry_name:
current_user
.
name
,
entry_email:
current_user
.
email
},
<%=
link_to
"Apply"
,
apply_path
(
job_id:
@job
.
id
),
class:
"btn btn-secondary"
%>
<%
else
%>
<%=
link_to
"Apply"
,
apply_path
(
job_id:
@job
.
id
),
class:
"btn btn-secondary"
%>
<%
end
%>
<%=
link_to
'Back'
,
:back
,
class:
"btn btn-secondary"
%>
<%=
link_to
'Back'
,
:back
,
class:
"btn btn-secondary"
%>
</section>
</aside>
</div>
app/views/user_mailer/job_apply.html.erb
View file @
13c666b9
...
...
@@ -2,7 +2,7 @@
<p>
Job title:
<%=
@job
.
title
%>
</p>
<p>
Location:
<%=
@job
.
cities
.
first
.
name
%>
</p>
<p>
Company:
<%=
Company
.
find
(
@job
.
company_id
)
.
name
%>
</p>
<p>
Company:
<%=
@job
.
company
.
name
%>
</p>
<p>
Your submitted information:
</p>
<p>
Full Name:
<%=
@user
.
name
%>
</p>
...
...
app/views/user_mailer/job_apply.text.erb
View file @
13c666b9
...
...
@@ -2,7 +2,7 @@ Dear <%= @user.name %>
Job title:
<%=
@job
.
title
%>
Location:
<%=
@job
.
cities
.
first
.
name
%>
Company:
<%=
Company
.
find
(
@job
.
company_id
)
.
name
%>
Company:
<%=
@job
.
company
.
name
%>
Your submitted information:
Full Name:
<%=
@user
.
name
%>
...
...
config/routes.rb
View file @
13c666b9
Rails
.
application
.
routes
.
draw
do
root
to:
'jobs#home'
resources
:entries
resources
:entries
,
only:
[
:new
,
:create
,
:show
,
:edit
,
:update
]
get
'/apply'
,
to:
'entries#new'
resources
:jobs
do
...
...
db/migrate/20180607084045_devise_create_users.rb
View file @
13c666b9
...
...
@@ -5,9 +5,10 @@ class DeviseCreateUsers < ActiveRecord::Migration[5.2]
create_table
:users
do
|
t
|
t
.
string
:name
,
null:
false
,
default:
''
t
.
string
:prefix
,
default:
''
t
.
string
:prefix
,
default:
''
t
.
string
:phone
,
default:
''
t
.
boolean
:registration
,
default:
false
t
.
text
:address
## Database authenticatable
t
.
string
:email
,
null:
false
,
default:
''
...
...
db/migrate/20180612070531_create_entries.rb
View file @
13c666b9
...
...
@@ -5,6 +5,8 @@ class CreateEntries < ActiveRecord::Migration[5.2]
t
.
references
:job
,
foreign_key:
true
t
.
string
:entry_name
t
.
string
:entry_email
t
.
string
:entry_phone
t
.
text
:entry_address
t
.
timestamps
end
...
...
db/schema.rb
View file @
13c666b9
...
...
@@ -52,6 +52,8 @@ ActiveRecord::Schema.define(version: 2018_06_19_011959) do
t
.
bigint
"job_id"
t
.
string
"entry_name"
t
.
string
"entry_email"
t
.
string
"entry_phone"
t
.
text
"entry_address"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
index
[
"job_id"
],
name:
"index_entries_on_job_id"
...
...
@@ -111,6 +113,7 @@ ActiveRecord::Schema.define(version: 2018_06_19_011959) do
t
.
string
"prefix"
,
default:
""
t
.
string
"phone"
,
default:
""
t
.
boolean
"registration"
,
default:
false
t
.
text
"address"
t
.
string
"email"
,
default:
""
,
null:
false
t
.
string
"encrypted_password"
,
default:
""
,
null:
false
t
.
string
"reset_password_token"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment