Hey Usman, you can use driver.switch_to.alert method to handle the javascript alert popup. This method switches the focus from default window to Javascript alert popup, so that necessary action can be done. Checkout the following example to understand better:
driver = Selenium::WebDriver.for :firefox
driver.get 'http://the-internet.herokuapp.com/javascript_alerts'
driver.find_elements(css: 'button')[1].click
alert_popup = driver.switch_to.alert
alert_popup.accept
result = driver.find_element(id: 'result').text
expect(result).to eql('You clicked: Ok')