added course add and edit

This commit is contained in:
Harry Bomrah 2017-09-22 00:13:22 +08:00
parent 68558c166b
commit eeb2b68def
8 changed files with 81 additions and 11 deletions

View File

@ -11,9 +11,41 @@ class Admin::InternationalRecruitsController < OrbitAdminController
redirect_to admin_international_recruits_path
end
def add_course
@course = UniversityCourse.new
end
def create_course
course = UniversityCourse.new(course_params)
course.save
redirect_to courses_admin_international_recruits_path
end
def edit_course
@course = UniversityCourse.find(params[:id])
end
def update_course
course = UniversityCourse.find(params[:id])
course.update_attributes(course_params)
course.save
redirect_to courses_admin_international_recruits_path
end
def courses
@table_fields = ["international_recruit.course_name", "international_recruit.actions"]
@courses = UniversityCourse.all.asc(:created_at)
end
def delete_course
course = UniversityCourse.find(params[:id])
course.destroy
redirect_to courses_admin_international_recruits_path
end
private
def course_params
params.require(:university_course).permit!
end
end

View File

@ -2,6 +2,7 @@ class InternationalRecruitsController < ApplicationController
def index
countries = []
session = OrbitHelper.request.session
courses = UniversityCourse.all.asc(:created_at).collect{|uc| [uc.course_name]}
InternationalCountry::LIST.keys.each do |countrykey|
countries << [InternationalCountry::LIST[countrykey], countrykey]
end
@ -15,7 +16,8 @@ class InternationalRecruitsController < ApplicationController
"countries" => countries,
"years" => years,
"member" => session["current_pseudo_user_id"],
"login_url" => login_url
"login_url" => login_url,
"courses" => courses
}
end

View File

@ -56,9 +56,9 @@ class RecruitApplication
# //Course Choice//
field :course_choice_one_id
field :course_choice_two_id
field :course_choice_three_id
field :course_choice_one
field :course_choice_two
field :course_choice_three
# //General Options//

View File

@ -0,0 +1,14 @@
<%= form_for @course, :url => {:action => "create_course"}, html: {class: "form-horizontal main-forms"} do |f| %>
<div class="control-group">
<%= f.label :course_name, :class => "control-label muted" %>
<div class="controls">
<%= f.text_field :course_name %>
</div>
</div>
<div class="control-group">
<div class="controls">
<%= f.submit "Save", :class => "btn btn-primary" %>
<a class="btn btn-default" href="<%= courses_admin_international_recruits_path %>">Cancel</a>
</div>
</div>
<% end %>

View File

@ -10,13 +10,16 @@
<% @courses.each do |course| %>
<tr>
<td><%= course.course_name %></td>
<td></td>
<td>
<a href="<%= delete_course_admin_international_recruit_path(course) %>" class="btn btn-danger" data-method="delete" data-confirm="Are you sure?">Delete</a>
<a href="<%= edit_course_admin_international_recruit_path(course) %>" class="btn btn-warning">Edit</a>
</td>
</tr>
<% end %>
</tbody>
</table>
<div class="bottomnav clearfix">
<div class="pull-right">
<a href="" class="btn btn-primary">Add</a>
<a href="<%= add_course_admin_international_recruits_path %>" class="btn btn-primary" id="add-course">Add</a>
</div>
</div>

View File

@ -0,0 +1,14 @@
<%= form_for @course, :url => {:action => "update_course"}, html: {class: "form-horizontal main-forms"} do |f| %>
<div class="control-group">
<%= f.label :course_name, :class => "control-label muted" %>
<div class="controls">
<%= f.text_field :course_name %>
</div>
</div>
<div class="control-group">
<div class="controls">
<%= f.submit "Save", :class => "btn btn-primary" %>
<a class="btn btn-default" href="<%= courses_admin_international_recruits_path %>">Cancel</a>
</div>
</div>
<% end %>

View File

@ -253,7 +253,7 @@
</tr>
<tr>
<td>
<select name="Department" id="Department"></select>
<%= f.select :course_choice_one, data["courses"] %>
</td>
</tr>
<tr>
@ -263,8 +263,7 @@
</tr>
<tr>
<td>
<select name="Department_Two" id="Department_Two">
</select>
<%= f.select :course_choice_two, data["courses"] %>
</td>
</tr>
</tbody>
@ -275,8 +274,7 @@
</tr>
<tr>
<td>
<select name="Department_Three" id="Department_Three">
</select>
<%= f.select :course_choice_three, data["courses"] %>
</td>
</tr>
</tbody>

View File

@ -6,6 +6,13 @@ Rails.application.routes.draw do
resources :international_recruits do
collection do
get "courses"
get "add_course"
post "create_course"
end
member do
get "edit_course"
patch "update_course"
delete "delete_course"
end
end
end