3 Replies Latest reply on Jul 30, 2013 12:46 AM by Stanislav Volodarskiy

    Assosiaction between two models

      Hello,

       

      I have two models cost and drivingresults and they are connected. Now I can show the drivingresults_id on the views of cost.

      But is there a possibility to show more attributes of the model drivingresults in cost?

       

      I want to add some code ;).

       

      new erb.

       

             <form method="POST" action="<%= url_for :action => :create %>">
                 <input type="hidden" name="id" value="<%= @cost.object %>"/>
               <h4 class="groupTitle">Please select your Drive first</h4>
                      <ul>
                      <li><select name="cost[drivingresults_id]">
                      <% @drivingresults.each do |drivingresults|%>
                      <option value="<%= drivingresults.object%>"
                      <%= "selected" if drivingresults.object == @cost.drivingresults_id%>
                      >
                      <%= drivingresults.ttime %></option>
                      <%end%>
                      </select>
                      </li>
                      </ul> 

       

      show.erb

       

            <li>
            <div class="itemLabel">total Costs electric </div>
                        <div class="itemValue"><%@drivingresults.km %></div>
                     </li>
      controller

       

      @km = DrivingResults.find_by_sql("SELECT drivingresults.km FROM DrivingResults WHERE drivingresults.object = drivingresults_id")
            render :action => :show, :back => url_for(:action => :index)

       


      I try to make a sql query, but i get this error:

       

      Params: {"id"=>"143478197185181.94", "cost"=>{"drivingresults_id"=>"143458892851316.0", "fuel"=>"1.536", "cs"=>"1"}}
      I 07/19/2013 16:03:23:305 00016624           HttpServer| GC Start.
      I 07/19/2013 16:03:23:305 00016624           HttpServer| GC End.
      I 07/19/2013 16:03:23:315 00016624           HttpServer| Process URI: '/app/Cost/overview'
      I 07/19/2013 16:03:23:315 00016624                  APP| RHO serve: /app/Cost/overview
      I 07/19/2013 16:03:23:315 00016624                  APP| eval_compiled_file : C:/workspace/smartecd/app/Cost/overview.erb
      I 07/19/2013 16:03:23:315 00016624           HttpServer| GC Start.
      I 07/19/2013 16:03:23:315 00016624           HttpServer| GC End.
      I 07/19/2013 16:03:23:325 000166b0         QtMainWindow| WebView: URL changed
      I 07/19/2013 16:03:26:466 00016624           HttpServer| Process URI: '/app/Cost/{143478197185182.94}/show'
      I 07/19/2013 16:03:26:466 00016624                  APP| RHO serve: /app/Cost/{143478197185182.94}/show
      I 07/19/2013 16:03:26:466 00016624                  APP| Params: {"id"=>"{143478197185182.94}"}
      I 07/19/2013 16:03:26:466 00016624                  APP| exception when running query: could not prepare statement: 1; Message: no such column: drivingresults_id
      I 07/19/2013 16:03:26:466 00016624                  APP| App error: could not prepare statement: 1; Message: no such column: drivingresults_id
      C:/MotorolaRhoMobileSuite2.1.1.7/ruby/lib/ruby/gems/1.9.1/gems/rhodes-3.4.2/lib/framework/rhom/rhom_db_adapter.rb:137:in `execute'
      C:/MotorolaRhoMobileSuite2.1.1.7/ruby/lib/ruby/gems/1.9.1/gems/rhodes-3.4.2/lib/framework/rhom/rhom_db_adapter.rb:137:in `_execute_sql'
      C:/MotorolaRhoMobileSuite2.1.1.7/ruby/lib/ruby/gems/1.9.1/gems/rhodes-3.4.2/lib/framework/rhom/rhom_db_adapter.rb:126:in `execute_sql'
      C:/MotorolaRhoMobileSuite2.1.1.7/ruby/lib/ruby/gems/1.9.1/gems/rhodes-3.4.2/lib/framework/rhom/rhom_object_factory.rb:1117:in `find_by_sql'
      C:/workspace/smartecd/app/Cost/cost_controller.rb:20:in `show'
      C:/MotorolaRhoMobileSuite2.1.1.7/ruby/lib/ruby/gems/1.9.1/gems/rhodes-3.4.2/lib/framework/rho/rhocontroller.rb:104:in `serve'
      C:/MotorolaRhoMobileSuite2.1.1.7/ruby/lib/ruby/gems/1.9.1/gems/rhodes-3.4.2/lib/framework/rho/rhoapplication.rb:226:in `serve'
      C:/MotorolaRhoMobileSuite2.1.1.7/ruby/lib/ruby/gems/1.9.1/gems/rhodes-3.4.2/lib/framework/rho/rho.rb:879:in `serve'
      I 07/19/2013 16:03:26:466 00016624           HttpServer| GC Start.
      I 07/19/2013 16:03:26:466 00016624           HttpServer| GC End.

       

      thanks for help!