From 7d62c292cb4e7a546ad0d3cc95b1411fd49cd866 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Thu, 21 Mar 2013 00:04:44 -0500 Subject: [PATCH] VRFS-278 musician_instruments are now populated on signup failure --- app/controllers/users_controller.rb | 2 +- app/views/users/new.html.erb | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 8bb89da35..b884d7323 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -77,6 +77,7 @@ class UsersController < ApplicationController # render any @user.errors on error load_location(request.remote_ip, location) gon.signup_errors = true + gon.musician_instruments = instruments render 'new' else if @user.email_confirmed @@ -186,7 +187,6 @@ class UsersController < ApplicationController # also, make up priority because we don't ask for it (but users can fix it later on their profile) priority = 0 original_instruments.each do |key, value| - logger.debug("key #{key} value:#{value}") if !value["selected"].nil? instruments << { :instrument_id => key, :proficiency_level => value["proficiency"].to_i, :priority => priority } priority = priority + 1 diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index 9ccaa7dc3..02aa4eabf 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -125,8 +125,8 @@ <% Instrument.standard_list.each do |instrument| %> - - + + <% end %>
<%= instrument.description %>_checkbox" name="jam_ruby_user[instruments][<%= instrument.id %>][selected]" type="checkbox" /><%= instrument.description %>
@@ -173,6 +173,15 @@ } } + // populate musician instruments from previous submit, if applicable + if(window.gon && gon.musician_instruments) { + $(gon.musician_instruments).each(function(index, value) { + $('#' + value.instrument_id.replace(" ", "") + "_checkbox").attr("checked", true); + $('#' + value.instrument_id.replace(" ", "") + "_proficiency").val(value.proficiency_level.toString()) + }) + } + + // show signup errors, if any if(window.gon && gon.signup_errors) { var errors = <%= @user.errors.to_json.html_safe %>