通过使用Rails重构删除重复的表单代码

时间:2012-05-11 07:03:05

标签: ruby-on-rails ruby-on-rails-3 refactoring ruby-on-rails-3.2 code-duplication

Finished in 15.53 seconds
←[31m86 examples, 4 failures←[0m

失败的例子:

←[31mrspec ./spec/requests/user_pages_spec.rb:95←[0m ←[36m# User pages signup wi
th valid information should create a user←[0m
←[31mrspec ./spec/requests/user_pages_spec.rb:104←[0m ←[36m# User pages signup w
ith valid information after saving the user ←[0m
←[31mrspec ./spec/requests/user_pages_spec.rb:105←[0m ←[36m# User pages signup w
ith valid information after saving the user ←[0m
←[31mrspec ./spec/requests/user_pages_spec.rb:106←[0m ←[36m# User pages signup w
ith valid information after saving the user ←[0m

不明白为什么我得到这个错误。我遵循了红宝石指南中的说明,问题5 .. http://ruby.railstutorial.org/chapters/updating-showing-and-deleting-users?version=3.2#sec:updating_deleting_exercises

应用程序/视图/用户/ new.html.erb

<%= provide(:title, 'Sign up') %>
<h1>Sign up</h1>

<div class="row">
<div class="span6 offset3">
<%= form_for(@user) do |f| %>
<%= render 'fields', f: f %>
<%= f.submit "Create my account", class: "btn btn-large btn-primary" %>
<% end %>
</div>
</div>

应用程序/视图/用户/ edit.html.erb

<%= provide(:title, 'Edit user') %>
<h1>Update your profile</h1>

<div class="row">
<div class="span6 offset3">
<%= form_for(@user) do |f| %>
<%= render 'fields', f: f %>
<%= f.submit "Save changes", class: "btn btn-large btn-primary" %>
<% end %>

<%= gravatar_for @user %>
<%= link_to "change", "http://gravatar.com/emails", :target => "_new"%>

</div>
</div>

应用程序/视图/用户/ _fields.html.erb

<%= render 'shared/error_messages' %>

<%= f.label :name %>
<%= f.text_field :name %>

<%= f.label :email %>
<%= f.text_field :email %>

<%= f.label :password %>
<%= f.password_field :password %>

<%= f.label :password_confirmation, "Confirm Password" %>
<%= f.password_field :password_confirmation %>

当我不尝试解决重构此代码并将其重复时我没有错误..所以我在想 /spec/requests/user_pages_spec.rb 并不是真的有问题..任何建议将不胜感激。

并且它很奇怪因为应用程序似乎没有任何问题(或者它似乎没有任何问题)但是它完全正常工作......它只是那个错误让我烦恼。

-Marc

0 个答案:

没有答案