Topic: Arrays and chosse one


I am newbie on ruby and I have questions and troubles, can you help me out?

This is the html and  the view

<select name="select" multiple size="3">
<option value="audi">Audi</option>
<option value="bmw">BMW</option>
<option value="dodge">Dodge</option>
<option value="nissan">Nissan</option>
<option value="renault">Renault</option>

The idea is to choose only one and that one show another list box with some results, for example:

I want an audi, I selected the audi and then another list box shows the types of audi: sedan, coupe,.....

This the code I have:

  def type
      @audi=['audi 1','audi 2','audi 3','audi 4']
      @bmw=['bmw 1','bmw 2','bmw 3','bmw 4']
      @dodge=['dodge 1','dodge 2','dodge 3','dodge 4']
      @nissan=['nissan 1','nissan 2','nissan 3','nissan 4']
      @renault=['renault 1','renault 2','renault 3','renault 4']
        case option
        when audi
          puts @audi
        when bmw
          puts @bmw
        when dodge
          puts @dodge
        when nissan
          puts @nissan
        when renault
          puts @renault      


This code is bad?, good?, something are missing.?
thanks for the help

Re: Arrays and chosse one

I think that you can use something like this

def type
  cars = {audi: ['audi 1', 'audi 2', 'audi 3', 'audi 4'], bmw: ['bmw 1', 'bmw 2', 'bmw 3', 'bmw 4']}
  type = params[:select]

and better to move making cars hash from this method for initializing only once.