0

I'm trying to create a drop down box in rails and I'm getting an error and I'm hopping that someone can shed some light as to why.

Here is the error:

undefined method `bot_id' for #<Robot:0x007fa1d663cac0>

Robots class:

class Robot < ActiveRecord::Base
  attr_accessible :color1, :color2, :image, :name, :speed, :weapon_damage, :weapon_slots, :bot_id
  ROBOT_TYPES = Hash.new("Mini Bot" => "1", "Micro Bot" => "2", "Macro Bot" => "3")
  ....
  end

Form:

...
<div class="field">
    <%= f.label :bot_id %><br />
    <%= f.select :bot_id, Robot::ROBOT_TYPES%>
  </div>
...
3
  • $ bundle exec rake db:migrate Commented May 12, 2013 at 4:28
  • I've done db:migrate, are you suggesting that I include the bundle exec? Commented May 12, 2013 at 4:29
  • I tried that and it didn't work :( Commented May 12, 2013 at 4:30

1 Answer 1

3

For this to work, you must pass the second arg as a special options_for_select. There is a helper to convert your hash for you.

You should read:

select_tag

option_for_select

Try this:

<%= select_tag :bot_id, options_for_select(ROBOT_TYPES) %>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.