Forum: Ruby Select Options

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Rachel N. (Guest)
on 2009-05-27 18:40
(Received via mailing list)
Hello All,

I have some code per View, Controller, Model (below).  The issue I have
is, in the View, I need to pass the category['wsc_uid_pk'] data returned
from <% @list_service_categories.each do |category| %> to the snippit of
code that calls <% @list_web_serv_types.each do |servtype| %> in
Controller.  Can anyone give me a pointer on how to do this?  I have
Googled all day but to no avail and may not be searching the correct
terms to return the syntax needed.

List_service_catgories and list_web_serv_types are both defined in my
Model and called from my Controller for return to the View.

The backend is Oracle 10g database where I have the stored db package
with function calls.  We have implemented OCI8 to allow our Rails apps
to "talk" to Oracle.

Example of data currently returned to View from stored DB data:
Category: Television, Option List: Premium TV, Enhanced TV, Basic TV
Category: Internet,   Option List: Premium TV, Enhanced TV, Basic TV
                       (should be Premium Inet, Enhanced Inet, Basic
Inet)
Category: Telephone,  Option List: Premium TV, Enhanced TV, Basic TV
                       (should be Premium Phone, Enhanced Phone, Basic
Phone)

In my View:
<!-- some code here -->

<tr><td><u>Service</u></td></tr>
<% @list_service_categories.each do |category| %>
   <tr><td height="25px" align="left"  valign="top" ><%=
category['wsc_uid_pk'] %> <%= category['wsc_description'] %></td>
   <td height="25px" align="left"  valign="top" ><%=
check_box('internet', 'make_connection') %></td

   <td height="25px" align="left"  valign="top" style="display:
inline;" nowrap></td>

   <!-- next column: service category types -->
   <!-- insert code here to dynamically fill the data from database
based on category -->
   <td height="25px" align="left"  valign="top" style="display:
inline;" nowrap>
   <select name="list_web_serv_types" id="list_web_serv_types" size="1"
>
  <option value=""> </option>
  <% @list_web_serv_types.each do |servtype| %>
       <option value="<%= servtype['wbt_uid_pk'] %> "><%=
category['wsc_uid_pk'] %> <%= servtype['wbt_description'] %> </option>
  <% end %>
   </select>
   </td>

   <!-- next column: service category subtypes -->
</tr>
<% end %>

<!-- some more code here -->

In my Controller:
def list_services_available
# some code here...

##############################

wsc_code = wsc_description = wsc_uid_pk = ''
#RSN 05-23-2009
@list_service_categories = Customer.list_service_categories

##############################

wbt_code = wbt_description = wbt_uid_pk = ''
#RSN 05-23-2009
@list_web_serv_types =
Customer.list_web_serv_types(@list_service_categories[0]['wsc_uid_pk'])

##############################

# some more code here...
end

In my Model:
class Customer < ActiveRecord::Base
set_primary_key "cus_uid_pk"
CustomerID = :cus_uid_pk

# some definitions here...

def self.list_service_categories
  ActiveRecord::Base.connection.select("SELECT gdt_number1
wsc_uid_pk,gdt_alpha1  wsc_code, gdt_alpha2  wsc_description FROM
table(service_availability_web_pkg.fn_get_service_cats)")
end

def self.list_web_serv_types(wsc_uid_pk) # called from customers
controller
  ActiveRecord::Base.connection.select("SELECT gdt_number1
wbt_uid_pk, gdt_alpha1 wbt_code, gdt_alpha2 wbt_description FROM
table(service_availability_web_pkg.fn_get_web_service_type(#{wsc_uid_pk}
))")
end

# some more definitions here...
end

Thank you,
Rachel S Nichol
Brian C. (Guest)
on 2009-05-27 18:55
Rails questions should be asked on a Rails mailing list. This one is for
Ruby (the programming language) not Rails (the web framework).

But the term you might want to Google for is "rails helper methods"
This topic is locked and can not be replied to.