1 Reply Latest reply on Oct 23, 2013 10:52 PM by Kutir Mobility

    How to dynamically generate buttons for Alert.show_popup

    Rob Richard

      I will admit that I'm a relative noob when it comes to ruby, but googling this has yielded no solutions, so thought I'd try the forum here.  I am trying to dynamically build a has for the id and title of the buttons has of the Alert.show_popup, but am not quite getting it.  What I want the end result to be is:

       

            Alert.show_popup( {

              :message => 'Please Select Appropriate Address:',

              :title => 'Get Nearby...',

              :icon => :info,

              :buttons => [

                {'id' => '1', 'title' => 'Address 1'},

                {'id' => '2', 'title' => 'Address 2'},

                {'id' => '3', 'title' => 'Address 3'},

                {'id' => '4l', 'title' => 'Address 4'}

              ],

              :callback => url_for(:action => :on_addressidentified_popup)

            }

            )

       

      I've tried a few methods, but none have worked (build a string that looks like a hash and try_convert, etc.).  Here was the latest one I tried which seemed close, but yet still far away:

       

       

            nearbyaddresses = Rho::JSON.parse(@params['body'])

       

            hOptions = Hash.new

                

            nearbyaddresses.each do |location|

              index = "'" + intIndex.to_s + "'"

              loc = "'" + location["Address"] + "'"

              opt = {'id' => index, 'title' => loc }

              hOptions.merge(opt)

              intIndex = intIndex + 1

            end

       

            Alert.show_popup( {

              :message => 'Please Select Appropriate Address:',

              :title => 'Get Nearby...',

              :icon => :info,

              :buttons => hOptions,

              :callback => url_for(:action => :on_addressidentified_popup)

            }

            )

       

       

      Any ruby wizards here that can help me out?