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

    How list Model items into another Rhomobile Model ?

      Hi,

       

      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:

      <li>

            <p>Invoice Lines</p>

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

      </li>

       

      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)

       

      Thanks.

       

      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(

                       :all,

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

              end

             render :back => '/app'

            end

           

          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| %>

               

                    <li>

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

                        <%= invoice.id %>

                       

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

                      </a>

                    </li>

               

                <% end %>

           

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

           

          ~Pietro

          1 of 1 people found this helpful