如何使自定义表单提交到devise中的user_session_path [英] How to make a custom form submit to the user_session_path in devise
本文介绍了如何使自定义表单提交到devise中的user_session_path的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用devise进行自定义表单登录。
这是我的代码
I am trying to make a custom form login using devise. This is the code I have
<h2>login</h2>
<%= form_for(:user, :url => user_session_path) do |f| %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="field">
<%= f.label :password %>
<% if @minimum_password_length %>
<em>(<%= @minimum_password_length %> characters minimum)</em>
<% end %><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<div class="actions">
<%= f.submit "Login" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
我在devise的帮助下生成了用户模型。
我收到以下错误
I generated the user model with the help of devise. I am getting the following error
undefined local variable or method `resource_name' for #<#<Class:0x007f8e54d29468>:0x007f8e49dd7500>
<%= link_to "Log in", new_session_path(resource_name) %><br />
这是我遵循的源码
将设计sign_in表单转换成Twitter Bootstrap Modal
推荐答案
如果您在application_helper.rb中设置了以下内容 -
If you have set up the followings in your application_helper.rb -
helper_method :resource_name, :resource, :devise_mapping
def resource_name
:user
end
def resource
@resource ||= User.new
end
def devise_mapping
@devise_mapping ||= Devise.mappings[:user]
end
然后,您应该可以执行以下操作 -
Then you should be able to do the following -
form_for(resource, :as => resource_name)
这篇关于如何使自定义表单提交到devise中的user_session_path的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文