在应用程序中的任意位置显示自定义 Sign_UP 表单
我想在我的申请表上的任何位置显示 Sign_UP 表单。我只知道如何使用登录表单执行此操作,但使用登录表单时,相同的方法不起作用。
[...]
<% unless user_signed_in? %>
<%= form_for("user", :url => user_session_path) do |f| %>
[...]
我在论坛上尝试了很多天来寻找这个问题的解决方案。我希望这里有人能帮助我。
谢谢!
I'd like to show a sign_UP form in anywhere on my application. I just know how to do this with a sign_in form, but with the sign_up form, the same method dont work.
[...]
<% unless user_signed_in? %>
<%= form_for("user", :url => user_session_path) do |f| %>
[...]
I am trying for many days on the forums to find a solution for this issue. I hope someone here can help me.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我成功做到这一点的方法。
我已将注册表单放入我的
home#index
我的文件中:
view/home/index.html.erb
helper/home_helper.rb
您需要该部分,因为 Devise 使用名为
resource
的东西,并且应该对其进行定义,以便您可以在任何地方调用您的registration#new
。这样,您应该就可以注册了。但是,我需要在同一页面上显示错误。这是我添加的内容:
layout/home.html.erb(索引视图使用的布局)
我找到了此代码这里
这是我创建的内容:如果在会话中无效,我会保存我的资源对象,这样用户就不必再次填写每个字段。我想存在更好的解决方案,但它有效并且对我来说足够了;)
controller/registration_controller.rb
我想我没有忘记任何代码。请随意使用您需要的任何东西。
干杯!
Here's how I managed to did it.
I've put a sign up form in my
home#index
My files:
view/home/index.html.erb
helper/home_helper.rb
You need that part because Devise works with something called
resource
and it should be defined so you can call yourregistration#new
anywhere.Like that, you should be able to register. However, I needed to display errors on the same page. Here's what I added:
layout/home.html.erb (the layout used by index view)
I found this code here
And here's something I created: I saved my resource object if invalid in a session so that the user hasn't to fill every field again. I guess a better solution exists but it works and it's enough for me ;)
controller/registration_controller.rb
I think I didn't forget any code. Feel free to use whatever you need.
Cheers !
从控制台
railsgenerate devise:install
。这将生成所有设备视图。之后,在视图
render 'devise/users/new'
或类似的内容中,现在无法检查语法。rails generate devise:install
from console. This will generate all devise views.After that in the view
render 'devise/users/new'
or something similar, cant check syntax now.