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开发者_JS百科.
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
I think rails wants the url parameter before update. Try switiching the order like this:
<%= link_to_remote "<", :url=>{:action=>'ajax_calendar',:month => (@date.beginning_of_month-1).strftime("%Y-%m")}, :update=>'calendar' %>
However, this probably isn't it. Your link_to_remote looks good, it's probably something in the controller. Could you show us your controller code for the action?
I was getting this error because of using both prototype and jquery together. removing jQuery solved this.
精彩评论