diff --git a/app/controllers/admin/international_recruits_controller.rb b/app/controllers/admin/international_recruits_controller.rb index 52e5679..5cd6901 100644 --- a/app/controllers/admin/international_recruits_controller.rb +++ b/app/controllers/admin/international_recruits_controller.rb @@ -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 \ No newline at end of file diff --git a/app/controllers/international_recruits_controller.rb b/app/controllers/international_recruits_controller.rb index fd29c95..cd0f1f1 100644 --- a/app/controllers/international_recruits_controller.rb +++ b/app/controllers/international_recruits_controller.rb @@ -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 diff --git a/app/models/recruit_application.rb b/app/models/recruit_application.rb index eb6deca..d730b30 100644 --- a/app/models/recruit_application.rb +++ b/app/models/recruit_application.rb @@ -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// diff --git a/app/views/admin/international_recruits/add_course.html.erb b/app/views/admin/international_recruits/add_course.html.erb new file mode 100644 index 0000000..0c0b26d --- /dev/null +++ b/app/views/admin/international_recruits/add_course.html.erb @@ -0,0 +1,14 @@ +<%= form_for @course, :url => {:action => "create_course"}, html: {class: "form-horizontal main-forms"} do |f| %> +
+ <%= f.label :course_name, :class => "control-label muted" %> +
+ <%= f.text_field :course_name %> +
+
+
+
+ <%= f.submit "Save", :class => "btn btn-primary" %> + Cancel +
+
+<% end %> \ No newline at end of file diff --git a/app/views/admin/international_recruits/courses.html.erb b/app/views/admin/international_recruits/courses.html.erb index 81bf936..13d5412 100644 --- a/app/views/admin/international_recruits/courses.html.erb +++ b/app/views/admin/international_recruits/courses.html.erb @@ -10,13 +10,16 @@ <% @courses.each do |course| %> <%= course.course_name %> - + + Delete + Edit + <% end %>
- Add + Add
\ No newline at end of file diff --git a/app/views/admin/international_recruits/edit_course.html.erb b/app/views/admin/international_recruits/edit_course.html.erb new file mode 100644 index 0000000..0e71c4d --- /dev/null +++ b/app/views/admin/international_recruits/edit_course.html.erb @@ -0,0 +1,14 @@ +<%= form_for @course, :url => {:action => "update_course"}, html: {class: "form-horizontal main-forms"} do |f| %> +
+ <%= f.label :course_name, :class => "control-label muted" %> +
+ <%= f.text_field :course_name %> +
+
+
+
+ <%= f.submit "Save", :class => "btn btn-primary" %> + Cancel +
+
+<% end %> \ No newline at end of file diff --git a/app/views/international_recruits/index.html.erb b/app/views/international_recruits/index.html.erb index 4c45411..f56948a 100644 --- a/app/views/international_recruits/index.html.erb +++ b/app/views/international_recruits/index.html.erb @@ -253,7 +253,7 @@ - + <%= f.select :course_choice_one, data["courses"] %> @@ -263,8 +263,7 @@ - + <%= f.select :course_choice_two, data["courses"] %> @@ -275,8 +274,7 @@ - + <%= f.select :course_choice_three, data["courses"] %> diff --git a/config/routes.rb b/config/routes.rb index 727db9f..a5aa3e8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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