通过AJAX更改link_to参数
changing link_to parameters via AJAX
我得到了这个链接
<%= link_to "show replies", tweets_show_replies_path(:parent => tweet, active: false ), method: :post, remote: true, class: "show-replies" %>
和这个函数在我的"tweets"控制器
def show_replies
@parent = Tweet.find(params[:parent])
@tweet = Tweet.new
respond_to do |format|
format.html {render :nothing => true}
format.js
end
end
这是我的 show_responses .js.erb
$('#tweet-<%= @parent.id %>').find('.replies').append(' <%=j render "tweets/replies" %> ');
我需要将"active"参数更改为true并在我的动词文件中更新它。但是我不知道如何读取rails参数并通过ajax更改它们。
我要给链接一个ID:
<%= link_to "show replies", tweets_show_replies_path(:parent => tweet, active: false ), method: :post, remote: true, id: "tweet-#{tweet.id}-replies-link", class: "show-replies" %>
然后在show_responses .js中执行此操作。Erb更改href:
$("#tweet-#{@parent.id}-replies-link").attr("href", "<%= tweets_show_replies_path(:parent => @parent, active: true) %>");
相关文章:
- 函数参数中的数据与指定变量之间的任何性能差异
- 使用Express捕获参数
- 参数变量出现ngTable指令问题
- AngularJS:我可以跳过函数参数回调吗
- 如何使用skip参数使用angular ui引导进行服务器端分页
- 要求未定义JS回调参数
- 我的jQuery插件参数没有正确启动,遇到了问题
- 节点Js:How to catch a“;没有这样的文件或目录“;读取线模块出错
- 获取@ResponseBody的一部分作为主干和Spring MVC控制器之间的参数
- jquery设置为使用参数运行
- Javascript”;类“;带有参数的扩展
- 为什么grunt contrib connect的中间件选项的第三个参数是未定义的
- 函数未将值作为参数传递
- 如何在submit to sightly时将表单输入值作为参数传递给WCMUsePojo
- 将变量传递给第三个参数的 GSAP TimeLineLite.to() 不起作用
- 结合Supercrollorama,TweenMax.to中第二个参数的含义是什么
- 如何发送类似“<>"在参数中使用$.ajax-to-server
- How-to 在 Parse.Cloud.define() 中声明参数
- Youtube t=URL参数和'请参见To'API函数不太准确
- 如何使用link-to从ember js传递和接收参数