How can I call a partial from an Ajax function, I need to render the content of a partial inside my home.html.erb, here the code:
<div class="span8">
<h3>Micropost Feed</h3>
<div class="posts">
<%= render 'feed' %>
</div>
</div>
At bottom I have a script, the problem code are in these lines:
if(nearBottomOfPage()) {
loading=true;
page++;
$.ajax({ // send an ajax-request to load the next page
url: '/feed?page=' + page,
type: 'get',
dataType: 'script',
success: function() { // after successfully completing the ajax-request redraw the sausage-navigation.
$(window).sausage('draw');
loading=false;
}
});
The "url" parameter is where I don't know what to write to call a partial, this partial is call _feed.html.erb and It's inside the same folder of Home.html.erb, finaly in my controller action I have this:
def home
if signed_in?
@post = current_user.posts.build
@feed_items = current_user.feed.order(:created_at).page(params[:page])
end
respond_to do |format|
format.js { render :partial => 'feed'}
format.html # index.html.erb
format.xml { render :xml => @feed_items }
end
end
How can I call that partial from the Ajax function?
Thanks a lot.