Rails Ajax不更新(Rails Ajax Not Updating)
如何在rails 2.3.8中使用Ajax更新页面的一部分?
我正在尝试制作带按钮的日历,以便进入下一个月和前几个月。 单击按钮,我希望日历更改,而无需重新加载整个页面。
我滚动浏览月份的按钮看起来像这样:
<%= link_to_remote "<",:update=>'calendar',:url=>{:action=>'ajax_calendar',:month => (@date.beginning_of_month-1).strftime("%Y-%m")} %>
这是我的主页,我已经渲染了部分。
index.html.erb <div id="calendar"> <%= render :partial=>'calendar' %> </div>
当我尝试使用firebug进行调试时,ajax调用正在被正确执行,我也从服务器获得了正确的响应,但是id'calender'没有得到更新。
有人可以指出我做错了什么吗?
提前致谢。
编辑:添加控制器
def ajax_calendar @events = Event.all @date = params[:month] ? Date.parse(params[:month].gsub('-', '/')) : Date.today render :partial => 'calender' end
How do i update a portion of a page using Ajax in rails 2.3.8?
i am trying to make a calendar with buttons to go to next and previous months. At the click of the buttons i want the calendar to change without reloading the whole page.
On of my buttons to scroll through months look like this:
<%= link_to_remote "<",:update=>'calendar',:url=>{:action=>'ajax_calendar',:month => (@date.beginning_of_month-1).strftime("%Y-%m")} %>
This is my main page where i have rendered the partial.
index.html.erb <div id="calendar"> <%= render :partial=>'calendar' %> </div>
when i tried to debug with firebug the ajax call is getting executed correctly and i am also getting the correct response from the server but the id 'calender' is not getting updated.
Can somebody please point out what i am doing wrong?
Thanks in advance.
Edit: Added controller
def ajax_calendar @events = Event.all @date = params[:month] ? Date.parse(params[:month].gsub('-', '/')) : Date.today render :partial => 'calender' end
原文:https://stackoverflow.com/questions/4172324