[英]Rails link_to tag
My route is: 我的路线是:
get "user" =>"user#info"
get "user/info"
It means that I set the user/info
as the default action of controller user
.When I visit the url http://192.168.0.198:3000/user
It works. 这意味着我将
user/info
设置为控制器user
的默认操作。当我访问URL http://192.168.0.198:3000/user
它起作用。
Now,I want to create a link: 现在,我想创建一个链接:
link_to 'Home',{:controller=>'user'}
But I got the error: 但是我得到了错误:
No route matches {:controller=>"user"}
If I write : 如果我写:
link_to 'Home',{:action=>'info':controller=>'user'}
It surely works. 当然可以。
But I just not want to write the action.So how should I do? 但是我只是不想写动作,那我该怎么办?
I get this in Rails API
我在
Rails API
得到这个
link_to "Profiles", controller: "profiles"
# => <a href="/profiles">Profiles</a>
Why I got Error? 为什么我出错?
尝试,
link_to 'Home',user_info_path
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.