4 Replies Latest reply on Sep 20, 2013 4:26 AM by Kutir Mobility

    How list Model items into another Rhomobile Model ?



      I'm working on an application for managing customers, products and invoices ( and invoices lines), so i created the rhomobile model for Customer(codeCustomer, name, city), Product(codeProduct, name, price), Invoice(invoicenum, date, codeCustomer) and Invoice lines(invoicenum, codeProduct, price, qte, total).


      What I want to do is show Customer, Product and Invoice in Index Page of my application. And Invoice lines when i add a new Invoice(with invoicenum = 2) and when click to show the Invoice data then i have a button that is used to show the Invoices Lines items with the the invoicenum with the invoicenum = 2 and i can add others in this list, basically i just show the Invoices lines items but for just the Invoice 2.


      So how i can do that ?

      I add this in the show.erb of Invoice Model:


            <p>Invoice Lines</p>

            <a href="app/Invoice/Invoicelines" class="ui-btn-right" data-icon="star">Show</a>



      but it's does not work and it's just for show all Invoices lines..


      Can you help me please ?


      And just another question when i click for add a new Invoice, how can replace the itemvalue of codeCustomer with a combobox with all the name of Customer(From the Customer Model)




      Ce message a été modifié par : RahXen Legacy

        • Re: How list Model items into another Rhomobile Model ?
          Pietro Francesco Maggi

          I think that what you're looking for is to load your invoice lines in an hash table in you controller, with something like:


            # GET /Order

            def index

              @invoices = Invoice.find(:all)

              @lines4invoice = {}

              @invoices.each do |i|

                   @lines4invoice[i.id] = InvoiceLine.find(


                       :conditions => {:invoiceId => i.id})


             render :back => '/app'



          This supposing that you've an invoiceId filed in your Invoice model.


          Then in your index.erb view you can use not only the @invoices array but even the @lines4invoice hash, just event showing a count of how many lines are in a given invoice (more or less):


                <% @orders.each do |order| %>



                      <a href="<%= url_for :action => :show, :id => invoice.object %>">

                        <%= invoice.id %>


                        <span class="ui-li-count" ><%= @lines4invoice[invoice.id].size %></span>




                <% end %>


          I wrote this without checking it in an app, but, excluding typos, it should works.



          1 of 1 people found this helpful