渲染:更新|页面|尝试渲染模板“更新”

发布于 2024-11-30 05:36:25 字数 1450 浏览 1 评论 0原文

我想做的是根据 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

聽兲甴掵 2024-12-07 05:36:25

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.

小帐篷 2024-12-07 05:36:25

好吧,由于 Prototype 已被弃用,我尝试了不同的解决方案:
LocalitiesController 现在返回数据,而不是脚本:

def index
@localities = Locality.all(:conditions => {:locality_type => params[:locality_type]},
                           :order => 'name')
render :inline => "<%= options_from_collection_for_select(@localities, 'id', 'name') %>"
end

该数据由 AJAX 处理,然后:

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;
}

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文