开发者

Reload page or div using RJS

开发者 https://www.devze.com 2023-02-01 19:16 出处:网络
I have a \'like\'-counter in a rails project. Whenever one clicks this \'like\'-link I want to add one to the like_counter in the database. The logic works well and the database is updated, but I cann

I have a 'like'-counter in a rails project. Whenever one clicks this 'like'-link I want to add one to the like_counter in the database. The logic works well and the database is updated, but I cannot figure out how to set up the Ajax Request correctly so it refreshes the page or the div when completed.

In my view this looks as follows:

<%= link_to_remote 'like', :url => {
                           :controller => 'projects', 
                           :action => 'like_it', 
                           :id=> @project.id }%>

The controller:

def like_it
    @project = Project.find(params[:id])
    @开发者_StackOverflow中文版project.update_like
    render :update do |page|
       page.reload
    end
end

the update_like method is in the model and just adds one to the counter and saves the project (this part works). As for the page.reload I Firefox throws an RJS-Error: ReferenceError: Reload is not defined. And the page is not reloaded

What do I do wrong? Is there a more distinguished way to just reload the div containing the counter? Any help is much appreciated!


Try:

render :update do |page|
    page << "window.location.reload()"
end
0

精彩评论

暂无评论...
验证码 换一张
取 消