1

I am getting this in my error list :

@error_messages = {
                   :password=>["can't be blank", "Password is required."], 
                   :"addresses.firstname"=>["can't be blank","Firstname is required."],
                   :"addresses.city"=>["can't be blank", "city is required."]
                  }

Here I want to remove the value "can't be blank" value from this hash so that I will get the validation error messages which was included by me.

is it possible to remove "can't be blank" value from above hash list and I will get this in result :

       @error_messages = {
                          :password=>["Password is required."],
                          :"addresses.firstname"=>["Firstname is required."],
                          :"addresses.city"=>["city is required."]
                         }

How to remove a specific value from a hash list(want to remove a specific value not a complete key,value pair).

1 Answer 1

5

Yes, possible.

@error_messages = {
                   :password=>["can't be blank", "Password is required."], 
                   :"addresses.firstname"=>["can't be blank","Firstname is required."],
                   :"addresses.city"=>["can't be blank", "city is required."]
                  }

@error_messages.each do |_,v|
   v.delete( "can't be blank" )
end

@error_messages
# => {:password=>["Password is required."],
#     :"addresses.firstname"=>["Firstname is required."],
#     :"addresses.city"=>["city is required."]}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.