# Create user field with options

**URL:** <https://meta.discourse.org/t/create-user-field-with-options/44427>\
**Category:** Development\
**Created:** [2016 年 5 月 18 日午前 6:23 UTC](https://meta.discourse.org/t/create-user-field-with-options/44427 "2016-05-18T06:23:01Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![alexu](https://avatars.discourse-cdn.com/v4/letter/a/5e9695/32.png) [@alexu](https://meta.discourse.org/u/alexu)\
**Post date:** [2016 年 5 月 18 日午前 6:23 UTC](https://meta.discourse.org/t/create-user-field-with-options/44427/1 "2016-05-18T06:23:01Z")

</div>

Hi I am playing around with the imports scripts and I want to create a drop down user field. The **ning** script has an example of creating a text field which I have working, and I am able to add a dropdown w/ no options, but when I change the type to drop down and add an options attribute like so

```
     @interests_field = UserField.find_by_name("My interests5")
     unless @interests_field
       @interests_field = UserField.create(name: "My interests5", description: "Do you like stuff5?", field_type: "dropdown", editable: true, required: true, show_on_profile: true, show_on_user_card: true, options: ['a','b', 'c'] )
     end

```

I get this error:

.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.6/lib/active\_record/attribute\_assignment.rb:59:in `rescue in \_assign\_attribute’: unknown attribute ‘options’ for UserField. (ActiveRecord::UnknownAttributeError)

I am new to ruby and discourse but I think the relevant code is in

./app/controllers/admin/user\_fields\_controller.rb

There is also a file

./spec/controllers/admin/user\_fields\_controller\_spec.rb

which suggests that options should be passable somehow?

Thanks to anyone who can shed light on this mystery.

Specifically how can I add options programmatically when creating a userfield in a ruby script situation.

---

_[View the full topic](https://meta.discourse.org/t/create-user-field-with-options/44427)._
