添加动态“帐户”关联?
我正在使用 Devise 插件进行用户登录。我想在此代码块中向用户显示“编辑”链接,以便它仅向已登录的用户显示,以便他们可以更改其帐户密码和电子邮件地址。我该如何在这段代码块中做到这一点?
rake 路径为: /users/edit(.:format) {:controller=>"devise/registrations", :action=>"edit"}
<div id="user_nav"> <%= link_to "Home | ", root_path %> <% if user_signed_in? %> Signed in as . Not you? <%= link_to "Sign Out", destroy_user_session_path %> <% else %> <%= link_to "Sign Up", new_user_registration_path %> or <%= link_to "Sign In", new_user_session_path %> <% end %> </div>
Am using the Devise plugin for user sign-in. I want to to display an 'edit' link to the user in this code block so it only displays to users who are logged in so they can change their account password and email address. How do I do it within this code block?
The rake route is: /users/edit(.:format) {:controller=>"devise/registrations", :action=>"edit"}
<div id="user_nav"> <%= link_to "Home | ", root_path %> <% if user_signed_in? %> Signed in as . Not you? <%= link_to "Sign Out", destroy_user_session_path %> <% else %> <%= link_to "Sign Up", new_user_registration_path %> or <%= link_to "Sign In", new_user_session_path %> <% end %> </div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只是在黑暗中拍摄...
但是...如果您使用,
您将获得有效路线的列表以及导致输出的字符串+字符串“_path”,之后它应该映射到您想要的内容。
在我们的应用程序上,我们禁用了设计/注册控制器,因此我不能只检查您,否则我会这样做:/但这里是其中一个会话的 rake 路由的输出行:
在这种情况下,感兴趣的字符串是“new_user_session”。添加 _path ,您最终会使用示例中使用的方法来登录...
Just a shot in the dark...
However...if you use
you'll get a list of valid routes and the string that leads off the output + the string "_path" after it should map to what you want.
On our app we've disabled the devise/registrations controller so I can't just check for you or I would have done that :/ But here is the line of output from rake routes for one of the session ones:
In this case, the string of interest is "new_user_session". Add _path and you wind up with the method you used in your example to log in...