我要做的是根据在 locality_type 选择中选择的选项更改可供选择的地区使用的列表。两个选择都在设施/_form.html.erb 上呈现。我在 LocalitiesController 中有以下代码
def index
@localities = Locality.all(:conditions => {:locality_type => params[:locality_type]},
:order => 'name')
loc_select_id = params[:element_id]
render (:update) do |page|
localities_options = options_from_collection_for_select(@localities, 'id', 'name')
page.replace_html loc_select_id, localities_options
end
end
这个方法是从 address.js 调用的,如下所示:
var locTypeElem = $('select#locality_type');
var locElem = $("select[name$='[locality_id]']");
var locQuery = '/localities?locality_type=' + locTypeElem.val()
+ '&element_id=' + locElem.attr('id')
$.get(locQuery, null, null, 'script');
我以前做过,但这次出了问题的是我在开发日志中收到以下错误消息:
ActionView::MissingTemplate (Missing template localities/update, application/update with {:formats=>[:js, "application/ecmascript", "application/x-ecmascript", :html, :text, :js, :css, :ics, :csv, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json], :locale=>[:ru, :ru], :handlers=>[:builder, :erb]}. Searched in:
* "D:/Work/Reserv.by/app/views"
* "D:/Dev_apps/Ruby187/lib/ruby/gems/1.8/gems/kaminari-0.12.4/app/views"
* "D:/Dev_apps/Ruby187/lib/ruby/gems/1.8/gems/devise-1.4.2/app/views"
):
app/controllers/localities_controller.rb:7:in `index'