我想在选中时显示所选人员的电子邮件。这是我到目前为止所得到的:
html.erb
<%= select_tag "", options_from_collection_for_select(Person.all, :id, :name), :id =>"test" %>
js.coffee
jQuery ->
$('select#test').change ->
$.get '/update_email/',{ id: $('option:selected', this). val() }
控制器
def update_email
@selected_person = Person.find(params[:id])
@email = @selected_person.email
end
如何显示@email?