use instrument id instead of description
This commit is contained in:
parent
e81a68f5c8
commit
b67a34d46d
|
|
@ -38,7 +38,9 @@ module JamRuby
|
|||
has_secure_password
|
||||
|
||||
before_save { |user| user.email = email.downcase }
|
||||
before_save :create_remember_token
|
||||
#before_save :create_remember_token
|
||||
|
||||
after_save :limit_to_five_instruments
|
||||
|
||||
validates :name, presence: true, length: {maximum: 50}
|
||||
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
|
||||
|
|
@ -76,7 +78,6 @@ module JamRuby
|
|||
|
||||
# helper method for creating / updating a User
|
||||
def self.save(params)
|
||||
|
||||
if params[:id].nil?
|
||||
user = User.new()
|
||||
else
|
||||
|
|
@ -116,11 +117,11 @@ module JamRuby
|
|||
|
||||
# loop through each instrument in the array and save to the db
|
||||
params[:instruments].each do |instrument|
|
||||
loaded_instrument = Instrument.find_by_description!(instrument[:description])
|
||||
mu = MusicianInstrument.new()
|
||||
|
||||
mu.user_id = user.id
|
||||
mu.instrument_id = loaded_instrument.id
|
||||
puts "INSTRUMENT ID #{instrument[:id]}"
|
||||
mu.instrument_id = instrument[:id]
|
||||
puts "proficiency level #{instrument[:proficiency_level]}"
|
||||
mu.proficiency_level = instrument[:proficiency_level]
|
||||
user.musician_instruments << mu
|
||||
end
|
||||
|
|
@ -132,6 +133,12 @@ module JamRuby
|
|||
return user
|
||||
end
|
||||
|
||||
def limit_to_five_instruments
|
||||
if instruments.count > 5
|
||||
errors.add(:instruments, "No more than 5 instruments are allowed.")
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def create_remember_token
|
||||
self.remember_token = SecureRandom.urlsafe_base64
|
||||
|
|
|
|||
Loading…
Reference in New Issue