link_to_remote不更新div

时间:2009-06-13 15:43:26

标签: ruby-on-rails ruby ajax

我正在使用link_to_remote异步更新div,但它不起作用。我必须刷新页面才能看到变化。

我用它来生成链接。 http://ruby.pastebin.com/m1d83be81


"padding-left:30px", :display => "table-row" ) do %>
 
  • { :success => 'entry_' + entry.id.to_s}, :url =>{ :controller => :entries, :action => :increment ,:id => entry.id}, :with => "'amount=' +prompt('Amount')")%> { :success => 'entry_' + entry.id.to_s}, :url =>{ :controller => :entries, :action => :decrement ,:id => entry.id}, :with => "'amount=' +prompt('Amount')")%> { :success => 'entry_' + entry.id.to_s}, :url =>{ :controller => :entries, :action => :update ,:id => entry.id}, :with => "'amount=' +prompt('Amount')")%>
  • 相应的操作都是这样的:

    
      def increment
        @entry = Entry.find(params[:id])
        @entry.amount += params[:amount].to_i
        @entry.save!
        render :partial=>"entry", :object=>@entry
      end
    
    

    2 个答案:

    答案 0 :(得分:1)

    删除update子句中的:success标记并测试:

    :update => 'entry_' + entry.id.to_s
    

    答案 1 :(得分:0)

    我发现在控制器操作中指定要更新的div是有帮助的。