的routes.rb
resources :rants,:except => [:show] do post '/Votes/:Vote',:controller => 'Votes',:action => 'create',:as => 'Vote'end
index.haml
%script{:ID => 'Vote_template',:type => 'text/x-handlebars-template'} .Votes = link_to 'up',rant_Vote_path(:rant_ID => '{{ID}}',:Vote => 'up') %span {{Votes}} = link_to 'down',:Vote => 'down')
的application.Js
var Vote_template = Handlebars.compile($('#Vote_template').HTML());
产量
<script ID="Vote_template" type="text/x-handlebars-template"> <div class='Votes'> <a href="/rants/%7B%7BID%7D%7D/Votes/up">up</a> <span>{{Votes}}</span> <a href="/rants/%7B%7BID%7D%7D/Votes/down">down</a> </div></script>
为了便于阅读,我简化了这个例子,但问题仍然存在;有没有办法使用{{}}作为参数的命名路由?我知道我可以做link_to’up’,’/ rants / {{ID}} / Vote / up’所以请不要提供它作为答案.
解决方法 问题是小胡子字符在URL中无效并且正在被转义.我建议创建一个包装器.def handlebar_path(helper,arguments={}) send("#{helper}_path",arguments).gsub(/%7B%7B(.+)%7D%7D/) do "{{#{}}}" endendhandlebar_path :rant_Vote,:rant_ID => '{{ID}}',:Vote => 'up'总结
以上是内存溢出为你收集整理的ruby-on-rails – 带有导轨的把手/胡须url_for全部内容,希望文章能够帮你解决ruby-on-rails – 带有导轨的把手/胡须url_for所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)