diff --git a/app/controllers/admin/books_controller.rb b/app/controllers/admin/books_controller.rb index 4c79966..8c87d3b 100644 --- a/app/controllers/admin/books_controller.rb +++ b/app/controllers/admin/books_controller.rb @@ -52,14 +52,50 @@ class Admin::BooksController < OrbitMemberController end def create - @member = MemberProfile.find(book_params['member_profile_id']) rescue nil - @book = Book.new(book_params) - @book.save - if params[:desktop] == "true" - render json: {"data" => get_paper_list}.to_json - else + + if !book_params['member_profile_id'].blank? + + @member = MemberProfile.find(book_params['member_profile_id']) rescue nil + @book = Book.new(book_params) + @book.save + + if params[:desktop] == "true" + render json: {"data" => get_paper_list}.to_json + else + redirect_to params['referer_url'] + end + + elsif !params[:author_members].blank? + + params[:author_members].each do |author_member| + + book_params['member_profile_id'] = author_member + @book = Book.new(book_params) + @book.save + + if params[:desktop] == "true" + render json: {"data" => get_paper_list}.to_json + end + + end + redirect_to params['referer_url'] + + else + + book_params['member_profile_id'] = User.find(current_user.id).member_profile_id + + @book = Book.new(book_params) + @book.save + + if params[:desktop] == "true" + render json: {"data" => get_paper_list}.to_json + end + + redirect_to params['referer_url'] + end + end def destroy diff --git a/app/views/admin/books/_form.html.erb b/app/views/admin/books/_form.html.erb index efb0712..ade0fd7 100644 --- a/app/views/admin/books/_form.html.erb +++ b/app/views/admin/books/_form.html.erb @@ -138,14 +138,27 @@