Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- модели
- class Bigbluebutton::Room < ActiveRecord::Base
- self.table_name = 'bigbluebutton_rooms'
- has_many :user_vebinar
- has_many :users, through: :user_vebinar
- accepts_nested_attributes_for :users, allow_destroy: false, reject_if: :all_blank
- end
- class User < ActiveRecord::Base
- self.table_name = 'model_people'
- has_many :user_vebinar
- has_many :rooms, through: :user_vebinar
- end
- class UserVebinar < ActiveRecord::Base
- self.table_name = 'users_vebinars'
- validates_presence_of :user, :room
- belongs_to :user
- belongs_to :room
- end
- controller
- class Bigbluebutton::RoomsController < ResourcesController
- def create_students
- if params[:bigbluebutton_room].present? and params[:bigbluebutton_room][:users_attributes].present?
- params[:bigbluebutton_room][:users_attributes].slice!(*params[:bigbluebutton_room][:users_attributes].keys.slice(0, Bigbluebutton::Room::USERS_ENTER_AT_ONCE))
- params[:bigbluebutton_room][:users_attributes].each do |(k,v)|
- if v[:full_name].present?
- names = (v[:full_name]+' - - -').split.slice(0,3)
- found_user = User.accessible_by(current_ability).find_or_create_by(
- :surname => names[0], :first_name => names[1], :middle_name => names[2]
- )
- v[:id] = !found_user.new_record? ? found_user.id : {}
- end
- end
- update! do |success, failure|
- # success.html {
- # if params[:save_and_continue].present?
- # render :create_students, notice: 'Учащиеся добавлены.'
- # else
- # redirect_to resource, notice: 'Учащиеся добавлены.'
- # end
- # }
- # success.js {
- # if params[:save_and_continue].present?
- # redirect_to url_for, notice: 'Учащиеся добавлены.'
- # else
- # flash[:notice] = 'Учащиеся добавлены.'
- # flash.keep(:notice)
- # render js: 'window.reload_page()', status: :ok
- # end
- # }
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement