why not extract this code into generate_url method which I suggested? Let's left it as much stupid as possible, similar to username and password