[英]How do you implement a dummy link_to in Rails 4
OK, so I'm just migrating my first project from Rails 3 to Rails 4, the project is under development and so has certain links that are only there for the sake of content. 好的,所以我只是将我的第一个项目从Rails 3迁移到Rails 4,项目正在开发中,因此有一些链接只是为了内容而存在。
In Rails 3 I could do this: 在Rails 3中,我可以这样做:
link_to "To be added", {:controller => "#", :action => "#"}
This would give me a dummy link that I could style etc. This does not work in Rails 4 due to a routing error: 这会给我一个虚拟链接,我可以设置样式等。由于路由错误,这在Rails 4中不起作用:
No route matches {:action=>"#", :controller=>"#"}
It could just be that I'm slightly sleep deprived at the moment but I can't seem to figure out a decent way of solving this and achieving the same functionality. 可能只是因为我现在略微睡眠不足,但我似乎无法找到解决这个问题并获得相同功能的好方法。
为什么不是这样的: link_to "To be added", "#"
?
我只是使用<%= link_to“添加”%>
So, it was definitely sleep deprivation, less than a minute after writing this I figured it out. 所以,这绝对是睡眠剥夺,写完之后不到一分钟我就明白了。
by using: 通过使用:
link_to "To be added", {:controller => "dummy", :action => "dummy"}
and adding a corresponding dummy route in the routes.rb file: 并在routes.rb文件中添加相应的虚拟路由:
get "dummy/dummy" => "dummy#dummy"
it all works again, yay 这一切都有效,耶
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.