简体   繁体   English

从不同的视图设计sign_up无法保存/创建用户

[英]Devise sign_up from different view fails to save/create user

I try to allow users to enter an email and password directly from my home/landing page. 我尝试允许用户直接从我的主页/登录页面输入电子邮件和密码。 For this I followed exactly this example: 为此,我完全按照以下示例进行操作:

http://pupeno.com/2010/08/29/show-a-devise-log-in-form-in-another-page/ http://pupeno.com/2010/08/29/show-a-devise-log-in-form-in-another-page/

So i placed the form in my index.html.erb and create a welcome_helper.rb like said in the article because my welcome controller controlls the index view homepage. 所以我将表单放在index.html.erb中,并按照本文中的说明创建了welcome_helper.rb,因为我的welcome控制器控制着索引视图的主页。

But what happens is that the user is not created / saved instead after hitting sign up I see this in the console: 但是发生的是,用户没有创建/保存,而是在点击注册后在控制台中看到的:

Started GET "/?utf8=%E2%9C%93&authenticity_token=mM52EgyczA4XgutnP37Q3rumj3HuHx8nYNRz5pas6lM%3D&user%5Bemail%5D=alex%2Bneun%40rivalfox.com&user%5Bpassword%5D=[FILTERED]&user%5Bremember_me%5D=0&commit=Sign+in" for 127.0.0.1 at 2014-01-21 14:24:21 +0100
Processing by WelcomeController#index as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"mM52EgyczA4XgutnP37Q3rumj3HuHx8nYNRz5pas6lM=", "user"=>{"email"=>"email@email.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
Rendered welcome/index.html.erb within layouts/application (3.1ms)
Completed 200 OK in 7ms (Views: 6.7ms | ActiveRecord: 0.0ms)

It seems that it is make a GET request, but I don't get why because the path is 100% the same as used on the normal Devise Sign Up page. 似乎是发出GET请求,但我不明白为什么,因为该路径与正常“ Devise Sign Up”页面上使用的路径相同100%。

Any thoughts how I can solve the problem. 任何想法我如何解决问题。 In the article I posted there is someone else asked for the same question, but no answer. 在我发布的文章中,有人问同样的问题,但没有答案。 Couldn't find anything on the net either. 在网上也找不到任何东西。

My index.html.erb looks like this: 我的index.html.erb看起来像这样:

<div class="col-lg-2 col-md-3 form-container">


<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do   
|f| %>
<%= devise_error_messages! %>

<div><%= f.label :email %><br />
<%= f.email_field :email, :autofocus => true %></div>

<div><%= f.label :password %><br />
<%= f.password_field :password %></div>

<div><%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %></div>

<div><%= f.submit "Sign up" %></div>
<% end %>

<%= render "devise/shared/links" %>

</div>

I think your :url => registration_path(resource_name) is not actually pointing to your create action. 我认为您的:url => registration_path(resource_name)实际上并不指向您的create动作。

This may not be the prettiest solution, but try replacing the first part of your form with this: 这可能不是最漂亮的解决方案,但是请尝试使用以下方法替换表单的第一部分:

<%= form_for(resource, :as => resource_name, :url => url_for(:controller => 'resource_controller', :action => 'create_action'), :method => :post) do |f| %>

Making sure you fill in the correct controller and action name. 确保输入正确的控制器和动作名称。

If this works, you know it was an issue with your url, you could then troubleshoot your existing :url selection to see what the appropriate url would be (or leave the solution as noted above). 如果这行得通,您就知道您的网址有问题,然后可以对现有的:url选择进行疑难解答,以查看适当的网址是什么(或退出上述解决方案)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM