Advertisement
alewtina

Untitled

Dec 16th, 2016
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 1.95 KB | None | 0 0
  1. модели
  2. class Bigbluebutton::Room < ActiveRecord::Base
  3.   self.table_name = 'bigbluebutton_rooms'
  4.  
  5.   has_many :user_vebinar
  6.   has_many :users, through: :user_vebinar
  7.  
  8.   accepts_nested_attributes_for :users, allow_destroy: false, reject_if: :all_blank
  9. end
  10.  
  11. class User < ActiveRecord::Base
  12.     self.table_name = 'model_people'
  13.     has_many :user_vebinar
  14.     has_many :rooms, through: :user_vebinar
  15. end
  16.  
  17. class UserVebinar < ActiveRecord::Base
  18.     self.table_name = 'users_vebinars'
  19.  
  20.     validates_presence_of :user, :room
  21.     belongs_to :user
  22.     belongs_to :room
  23. end
  24.  
  25.  
  26. controller
  27. class Bigbluebutton::RoomsController < ResourcesController
  28.    
  29. def create_students
  30.  
  31.         if params[:bigbluebutton_room].present? and params[:bigbluebutton_room][:users_attributes].present?
  32.             params[:bigbluebutton_room][:users_attributes].slice!(*params[:bigbluebutton_room][:users_attributes].keys.slice(0, Bigbluebutton::Room::USERS_ENTER_AT_ONCE))
  33.  
  34.             params[:bigbluebutton_room][:users_attributes].each do |(k,v)|
  35.                 if v[:full_name].present?
  36.                     names = (v[:full_name]+' - - -').split.slice(0,3)
  37.                     found_user = User.accessible_by(current_ability).find_or_create_by(
  38.                         :surname => names[0], :first_name => names[1], :middle_name => names[2]
  39.                     )
  40.                 v[:id] = !found_user.new_record? ? found_user.id : {}
  41.                 end
  42.             end
  43.             update! do |success, failure|        
  44.                 # success.html {
  45.                 #   if params[:save_and_continue].present?
  46.                 #       render :create_students, notice: 'Учащиеся добавлены.'
  47.                 #   else
  48.                 #       redirect_to resource, notice: 'Учащиеся добавлены.'
  49.                 #   end
  50.                 # }
  51.                 # success.js {
  52.                 #   if params[:save_and_continue].present?
  53.                 #       redirect_to url_for, notice: 'Учащиеся добавлены.'
  54.                 #   else
  55.                 #       flash[:notice] = 'Учащиеся добавлены.'
  56.                 #       flash.keep(:notice)
  57.                 #       render js: 'window.reload_page()', status: :ok
  58.                 #   end
  59.                 # }
  60.             end
  61.         end
  62.     end
  63. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement