render :update do |page| tries to render template "update"
what i'm trying to do is change the list of available for select localities, based on option selected in locality_type select. Both selects are rendered on the facilities/_form.html.erb . I have the following code in 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
This method is called from address.js like that:
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');
I didi it before, but what goes wrong this time is i get the following Error message in my development log:
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'
Prototype and RJS have been removed from Rails 3.1 to a separate gem prototype-rails
. Make sure you include it in your Gemfile.
Well, since Prototype is deprecated, I tried a different solution: LocalitiesController now returns data, not the script:
def index
@localities = Locality.all(:conditions => {:locality_type => params[:locality_type]},
:order => 'name')
render :inline => "<%= options_from_collection_for_select(@localities, 'id', 'name') %>"
end
This data is processed by AJAX then:
function selectLocalitiesByLocalityType()
{
var locTypeElem = $('select#locality_type');
var locElem = $("select[name$='[locality_id]']");
var locQuery = '/localities?locality_type=' + locTypeElem.val()
$.ajax({
url: locQuery,
method: 'GET',
dataType: 'html',
success: function(data) {
locElem.empty();
locElem.append(data);},
error: function(data) {alert(data);}
});
return false;
}
精彩评论