Rails 3-链接/按钮以运行ajax请求而无需重定向
链接运行ajax命令的最佳方式是什么(我在Rails 3.1中使用jquery)?到目前为止,我尝试使用一个链接,通过控制器操作“update_me”来运行代码Rails 3-链接/按钮以运行ajax请求而无需重定向,ajax,ruby-on-rails-3,model-view-controller,jquery,Ajax,Ruby On Rails 3,Model View Controller,Jquery,链接运行ajax命令的最佳方式是什么(我在Rails 3.1中使用jquery)?到目前为止,我尝试使用一个链接,通过控制器操作“update_me”来运行代码 views/products/new.html.erb包含以下行: <%= link_to "Update", :action => 'update_me' %> 但这会导致缺少模板错误: 缺少模板 缺少模板产品/update_me,应用程序/update_me与{:handlers=>[:erb,:builder,
views/products/new.html.erb
包含以下行:
<%= link_to "Update", :action => 'update_me' %>
但这会导致缺少模板错误:
缺少模板
缺少模板产品/update_me,应用程序/update_me与{:handlers=>[:erb,:builder,:coffee],:formats=>[:html],:locale=>[:en,:en]}。搜索位置:“/home/ubuntu/code/preevio/app/views”*“/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/Desive-1.4.3/应用程序/视图”
为什么我的视图中需要有一个
update_me.html.erb
?我想这就是他们想要的。我不能在控制器操作/方法中启动代码而不必查看它吗?还是我的方法不对?因为Rails在配置上有约定,Rails希望控制器中的操作有一个合适的视图
如果不希望渲染任何内容,请执行以下操作:
我知道这个答案有点晚了,但我把它贴在了任何其他可能来这里尝试做类似事情的人身上 如果您将html行更改为
<%= link_to "Update", :action => 'update_me', :remote => true %>
“更新”,:remote=>true%>
它应该有到所提供操作的链接,并为您执行ajax调用
您可以查看提供的链接以查看文档
更新操作是否发布或获取数据这会将我带到一个空白页面,即products/update\me。如何防止任何类型的重定向?为什么不使用jquery进行ajax调用呢?我认为$.ajax(“'update\u me”%>”)作为旁注,您还需要在控制器中使用render:nothing=>true。
render :nothing => true
<%= link_to "Update", :action => 'update_me', :remote => true %>