diff --git a/app/controllers/personal_journals_controller.rb b/app/controllers/personal_journals_controller.rb index 41d94ee..a112c4d 100644 --- a/app/controllers/personal_journals_controller.rb +++ b/app/controllers/personal_journals_controller.rb @@ -9,7 +9,7 @@ class PersonalJournalsController < ApplicationController journal_paper_query = journal_paper_query.where(:year.in => page.year.to_a ) end if (!page.journal_type.blank? rescue false) - journal_paper_query = journal_paper_query.where(:journal_type_id.in => page.journal_type.to_a ) + journal_paper_query = journal_paper_query.where(:journal_type_ids.in => page.journal_type.to_a ) end journal_papers = journal_paper_query.page(OrbitHelper.params[:page_no]).per(page_data_count) page = Page.where(page_id: params[:page_id]).first rescue nil diff --git a/app/models/journal_paper.rb b/app/models/journal_paper.rb index b63177f..9a92627 100644 --- a/app/models/journal_paper.rb +++ b/app/models/journal_paper.rb @@ -33,7 +33,7 @@ class JournalPaper #relations belongs_to :member_profile belongs_to :journal_paper_type - belongs_to :journal_type + has_and_belongs_to_many :journal_types has_and_belongs_to_many :journal_levels diff --git a/app/views/admin/journal_papers/_form.html.erb b/app/views/admin/journal_papers/_form.html.erb index 87fc8d5..70964c1 100644 --- a/app/views/admin/journal_papers/_form.html.erb +++ b/app/views/admin/journal_papers/_form.html.erb @@ -201,7 +201,7 @@
- <%= f.select :journal_type_id, @journal_types.collect {|t| [ t.title, t.id ]}, {include_blank: ''}, :class => "span3" %> + <%= f.select :journal_type_ids, @journal_types.collect {|t| [ t.title, t.id ]}, {include_blank: ''}, {multiple: true}, :class => "span3" %>
diff --git a/lib/tasks/personal_journal.rake b/lib/tasks/personal_journal.rake index 6299305..54a4dcb 100644 --- a/lib/tasks/personal_journal.rake +++ b/lib/tasks/personal_journal.rake @@ -1,4 +1,14 @@ -# desc "Explaining what the task does" -# task :personal_journal do -# # Task goes here -# end +namespace :personal_journal do + desc 'set_journal_type' + task :set_journal_type do |task,args| + JournalPaper.where(:rss2_id.ne=>nil).update_all({"$unset"=>{"journal_type_ids"=>""}}) + MemberTag.all.each do |mt| + journal_type = JournalType.where(:title=>mt.title).first + journal_type = JournalType.create(:title_translations=>mt.title_translations) if journal_type.nil? + journal_type_id = journal_type.id + journal_paper_ids = JournalPaper.where(:member_profile_id.in=>mt.member_profile_ids, :rss2_id.ne=>nil).pluck(:id) + JournalPaper.where(:id.in=>journal_paper_ids).update_all({"$addToSet"=>{"journal_type_ids"=>journal_type.id}}) + # JournalType.where(:id=>journal_type_id).update_all({"$addToSet"=>{"journal_paper_ids"=>{"$each"=>journal_paper_ids}}}) + end + end +end \ No newline at end of file