Jim ruther Nill wrote in post #1079179: > On Wed, Oct 10, 2012 at 5:01 PM, KUL KING <kulking...@gmail.com> wrote: > >>> And when user clicks on the "Add new option". A pop up dialog appears to >>> add a new value. And when I click create it hits the database and adds the >>> value to the db. >>> >>> But It never updates the dropdown list. Suggest me a way to auto refresh >>> only the current dropdown with the new vales in db when a new value is >>> added. >>> >> > It is possible to do this via ajax as KUL KING has said but you don't > need > to render the whole html. just return a json data with the id of > the new option. Then just append an option tag on the dropdown. > > >>> rubyonrails-talk+unsubscr...@googlegroups.com. >> To post to this group, send email to rubyonrails-talk@googlegroups.com. >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > > > --
Jim, Just return a json data with the id of the new option. Can you explain with some coded examples. My coffee script code looks like this: After directing to a dialog: root.add_new_item = -> val1 = document.getElementById("item_name").value val2 = document.getElementById("item_id").value $.ajax type: "POST" url: "/items.json" data: item: name: val1 item_id: val2 dataType: "json" success: (msg) -> alert "Item saved" + msg.name "I guess here I have to add changes to make dropdown refresh" error: (msg) -> alert "Item already exists" Ram -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.