设计部分的设计问题

时间:2013-08-20 16:14:49

标签: ruby-on-rails ruby

我为我的设计注册设计了一个自定义表单。但是,当我尝试创建新用户时,设计不会将数据发布到数据库,也不会创建用户。

我遵循设计文档

在我的应用程序控制器中我有

 def resource_name
    :user
  end

  def resource
    @resource ||= User.new
  end

  def devise_mapping
    @devise_mapping ||= Devise.mappings[:user]
  end

我在设计名称中做了一个部分:“_signup.html.erb”使用自定义表单并将其呈现在设计/注册/新

<%=render :partial => '/devise/signup', :locals => {:resource => resource}%>

我注册时没有错误显示 仅在日志中检查rails控制台时没有创建用户。需要一些帮助来弄清楚如何解决它。

Started GET "/users/sign_up?utf8=%E2%9C%93&authenticity_token=P0zVBHBKE2Ee8V3cRwtIJwAtO2txEaWEV3hGsRcqfno%3D&u
ser%5Bfirst_name%5D=Obed&user%5Bfirst_name%5D=lorisson&user%5Bemail%5D=obed.lorisson%40gmail.com&user%5Bpasswo
rd%5D=[FILTERED]&user%5Bpassword%5D=[FILTERED]&commit=Join+spotlight+Now" for 127.0.0.1 at 2013-08-20 12:11:40
 -0400
Processing by Devise::RegistrationsController#new as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"P0zVBHBKE2Ee8V3cRwtIJwAtO2txEaWEV3hGsRcqfno=", "user"=>{"fi
rst_name"=>"lorisson", "email"=>"obed.lorisson@gmail.com", "password"=>"[FILTERED]"}, "commit"=>"Join spotligh
t Now"}
  Rendered devise/shared/_links.erb (0.0ms)
  Rendered devise/_signup.html.erb (15.6ms)
  Rendered devise/registrations/new.html.erb within layouts/application (46.9ms)
  Rendered shared/_header.html.erb (0.0ms)
  Rendered shared/_flash_messages.html.erb (0.0ms)
  Rendered shared/_footer.html.erb (0.0ms)
Completed 200 OK in 156ms (Views: 156.2ms | ActiveRecord: 0.0ms)

注册表单

  <%= form_for(@user, :url => user_registration_path(@user)) do |f| %>

                                <%= devise_error_messages! %>

                                    <fieldset class="form_division">
                                        <div class="personal">
                                            <div class="controls">
                                              <%= f.text_field :first_name,  placeholder: 'first name ',:required => "true"%>
                                            </div>
                                        </div>

                                        <div class="personal">
                                            <div class="controls">
                                              <%= f.text_field :first_name,  placeholder: 'last name ',:required => "true"%>
                                            </div>
                                        </div>
                                   </fieldset>

                                    <div class="group">
                                        <div class="circle">
                                            <span>2</span>
                                        </div>
                                        <h3>Your account credentials</h3>
                                    </div>

                                   <fieldset class="form_division">
                                        <div class="credential">

                                            <div class="controls">
                                               <%= f.email_field :email, :autofocus => true ,placeholder: 'Email'%>
                                            </div>
                                        </div>

                                        <div class="credential">
                                            <div class="controls">
                                              <%= f.password_field :password, placeholder: 'Password' %>
                                            </div>
                                        </div>
                                        <div class="credential">
                                            <div class="controls">
                                              <%= f.password_field :password, placeholder: 'Password comfirmation' %>
                                            </div>
                                        </div>
                                    </fieldset>

                                    <div class="actions">
                                        <p>By signing up, you agree to our <span><a href="">terms</a></span> of use and <span><a href="">privacy policy</a></span> </p>

                                        <div class="shared_links">
                                          <%= render "devise/shared/links" %>
                                        </div>

                                        <div class="controls">
                                          <%= f.submit "Join spotlight Now", class: 'btn-signup animated wobble' %>
                                           <!--<a href="" class="btn-signup">join spotlight now</a>-->
                                        </div>
                                    </div>
                                <% end %>

呈现这就是它的样子

<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post">

1 个答案:

答案 0 :(得分:0)

发布您的自定义注册表单,似乎您提交错误的路径。看起来您正在将数据作为GET请求发送:

Started GET "/users/sign_up?utf8=%E2%9C%93&authenticity_t.......

应该(大致)看起来像这样:

Started POST "/users?params......

渲染时,您的表单应如下所示:

<form action="/users" id="new_user" method="post" >
...
</form>