渲染:更新|页面|尝试渲染模板“更新”
我想做的是根据 locality_type select 中选择的选项更改可用于选定地点的列表。两个选择都在设施/_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'
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'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Prototype 和 RJS 已从 Rails 3.1 中删除到单独的 gem
prototype-rails
。确保将其包含在 Gemfile 中。Prototype and RJS have been removed from Rails 3.1 to a separate gem
prototype-rails
. Make sure you include it in your Gemfile.好吧,由于 Prototype 已被弃用,我尝试了不同的解决方案:
LocalitiesController 现在返回数据,而不是脚本:
该数据由 AJAX 处理,然后:
Well, since Prototype is deprecated, I tried a different solution:
LocalitiesController now returns data, not the script:
This data is processed by AJAX then: