Advertisement
alewtina

Untitled

Jan 11th, 2017
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 1.18 KB | None | 0 0
  1. def graph_instructions_update
  2.  
  3.         attr = params[:user][:user_instruction_refs_attributes]['0']
  4.         head = Department.find_by_id(resource.department_id) if resource.department_id
  5.         program = Course.find_by_id(attr[:instruction_id]) if attr[:instruction_id].present?
  6.  
  7.         @session = @user.sessions_upcoming.find_or_create_by(
  8.             user_id: @user.id ,
  9.             head_user_id: head.head_id,
  10.             instruction_id: (attr[:instruction_id] if attr[:instruction_id].present?),
  11.             allowed_period_start: (attr[:date] if attr[:date].present?),
  12.             program_code: (program.code if program),
  13.             program_title: (program.title if program),
  14.             program_item_id: 2571,
  15.             user_instruction_last: 1)
  16.  
  17.         params[:user][:user_instruction_refs_attributes]['0'][:session_id] = @session.id
  18.  
  19.         update! do |success, failure|
  20.             success.html { redirect_to graph_instructions_users_path, notice: 'Успешно сохранено.' }
  21.             success.js { render js: 'window.reload_page()', status: :ok }
  22.             failure.html { render :graph_instructions_edit }
  23.             failure.js { render js: 'alert("Нужно исправить ошибки:\n'+@user.errors.messages.values.flatten.join("\\n")+'")', status: :unprocessable_entity }
  24.         end
  25.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement