首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AJAX不渲染部分

AJAX不渲染部分
EN

Stack Overflow用户
提问于 2016-01-21 20:43:10
回答 1查看 74关注 0票数 0

我有一个名为events\new.html.erb的视图,它包含其他用户的集合选择。我想让它使得每次用户在集合select中选择一个不同的名字时,都会用所选用户的Calendar填充一个<div id="colleaguecal"></div>,其中包含他们的个人Events。然而,我似乎无法获得保存我想要呈现的日历的部分calendars\_showColleague.html.erb,以便在更改集合选择时实际出现……

代码语言:javascript
复制
#events\new.html.erb

<%= f.collection_select :id,
                                Customer.where(business_id: current_customer.business_id),
                                :id,
                                :full_name,
                                { prompt: 'Select' },
                                { id: "colleageselect", onChange: "renderColCal(this)" } %>
代码语言:javascript
复制
#application.js
function renderColCal(select){

    var colleagueID = select.value ; //this variable is sent to Ruby for the database query to find the selected user
    $(document).on("change", "select#id", function(e){

            $.get("customers/"+ +$(this).val() + "/calendars/1");
        }
    );

}

。。

代码语言:javascript
复制
#routes.rb
post 'calendars_controller/calendarChange', to: 'calendars_controller#calendarChange'

然后在我的Calendars_controller#calendarChange中使用javascript var colleagueID

代码语言:javascript
复制
#calendars_controller.rb
class CalendarsController < ApplicationController
  respond_to :js, :html


  def new
    @calendar = Calendar.new(calendar_params)

  end

  def create
    @calendar = Calendar.new(calendar_params)
  end

private
  def calendar_params
    params.require(:customer_id)
  end


  def show
    @calendar = current_customer.calendar
    @events = @calendar.events
  end

  def calendarChange
    colleagueID = params[:colleagueID] #the JS var is taken in here and then used to find the user in the database
    @colleague = Customer.where(id: :colleagueID)

    @colcalendar = @colleague.calendar
    @events = @colleague.calendar.events #the specific events that I want to render to the '_showColleague.html.erb' template

  end

end

我需要在events\new.html.erb中呈现部分calendars\_showColleague.html.erb,其中向_showColleague传递在calendars#calendarChange中创建的@events@colcalendar变量。在客户与collection_select交互之前,应该没有任何内容,一旦他们选择了另一个客户,所选客户的日历(_showColleague)就会出现在下面。我该怎么做呢?

昨天我被告知要这样做,但它没有渲染任何内容:

代码语言:javascript
复制
#app/views/calendars/new.js.erb
$(".element").html("<%=j render 'calendars/_showColleague' %>");

请帮帮我!谢谢

EN

回答 1

Stack Overflow用户

发布于 2016-01-21 20:52:24

参考这一点,请注意,在渲染部分时不需要给出_(下划线)。

代码语言:javascript
复制
  $('.element').html("<%= escape_javascript(render :partial => 'calendars/showColleague') %>");
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34924185

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档