0 Replies Latest reply on Mar 18, 2012 4:46 PM by Hector Meza

    RhoMobile/Elements V2 tip on Model to Model Param passing { }

    Hector Meza

      RhoMobile Model to Model parameter passing tip - took a lot of trouble shooting to see that parameters were encased in { }.  Hope this save you all some time

      Special thanks to Geoff P for his assistance.


      Google group reference:



      Passing parameters other than supported options is passed in as a separate hash as follows:


      <%=link_to "Add another task",  :action => :new, :controller => "Task", :id => @list.object , :query => { :list_id => @list.list_id, :task_id => @list.task_id } %>


      Issue: When passing a parameter between models, the parameter will get enclosed in curly braces {}, doing a find with the unmodified parameter will not result in a find.

      Option 1 would be to strip the {}, i.e.


              tmp = @params['id']

          tmp = tmp.sub(/{/,'').to_s

          tmp = tmp.sub(/}/,'').to_s


      Option 2 (correct method) is to propery pass the parameter(s) with a supported option (Reference from above).

      Example usage:

      Model relationship is based on a 1 to many where Model 1 (Lookup = parent) and Model 2 (Tag = child)

      Code example 1:

      Call from a button on a form in the lookup model to the tag model


      <a href="<%= url_for :controller => :Tag, :action => :Taglist, :id =>     @lookup.object, :query => {:list_id => @lookup.SKU} %>" class="ui-btn-right" data-icon="star">




      In the above, “:list_id” is the parameter. 


      Usage of the parameter in the Tag_controller.rb example:


        def Taglist

           @tags = Tag.find(:all, :conditions => {'Sku' => @params['list_id']})

           render :back => '/app'



      Code example 2:

      Call from a button on a form in the tag model back to the form in the lookup model (back)


      <a href="<%= url_for  :controller => :Lookup, :action => :filter_sku_result, :id => @params['id'], :query => {:list_id => @params['list_id']}%>" class="ui-btn-left" data-icon="arrow-l" data-direction="reverse">





      Usage of the parameter in the lookup_controller.rb :

      def filter_sku_result

                  @lookup = Lookup.find(:first, :conditions => {'SKU' => @params['list_id']})

                  if @lookup

              render :action => :filter_sku_result, :back => url_for(:action => :index)


              Alert.show_popup "Item with SKU #{@params['list_id']} not found"

              redirect :action => :sku_lookup_form





      Hope this helps someone.