ratan
ratan

Reputation: 429

how to dynamically add a value to a drop down in rails

if I have a drop down on a page that lists some values which are in a DB table.

next to the drop down I have something which when clicked makes a text box. Kind of like Edit in place. is it possible to type some value there hit enter and have that value be loaded up in the drop down?

Upvotes: 1

Views: 284

Answers (1)

Sam Coles
Sam Coles

Reputation: 4043

If the select box is is a list of dongles, and Dongle is a resource:

In your SomethingElseController:

@new_dongle = Dongle.new

In your view:

<% remote_form_for @new_dongle do |dongle_form| %>
   <%= dongle_form.text_field :name %>
<% end %>

Check out the api docs for remote_form_for. If you want the id of the just created object, look at the callback parameters for link_to_remote on the same page.

Upvotes: 1

Related Questions