load partial with jquery and rails

后端 未结 5 1393
深忆病人
深忆病人 2021-01-04 23:54

Im curious about what the best way to load a rails partial with jquery. So far I have tried a solution not working:

$(\'#imagecontent\').load(\'/newsletters/         


        
5条回答
  •  情歌与酒
    2021-01-05 00:06

    The reason that code doesn't work is that rails doesn't expose view files outside. To achieve the thing you want, you'll need an action which would render this partial:

    def image_gallery
      render :partial => "image_gallery"
    end
    

    Also there is a plugin called jRails which replaces standard ajax helpers (which use prototype) with equivalent jquery-oriented ones. In your case you would use something like

    <%= remote_function(:update => "imagecontent", :url => "/newsletters/image_gallery") %>
    

    And even more, in Rails 3 you won't need it. See this link.

提交回复
热议问题