我正在做 Michael Hartl 的 railstutorial.org 并且我正在尝试做一个练习,在视图中分解出一个表格。这是本章的链接,问题与清单 10.5、10.6 和 10.7 相关。我试图弄清楚如何提供正确的:url
,至少我认为我正在这样做。
https://www.railstutorial.org/book/updating_and_deleting_users
这是我的代码:
_form.html.erb
<%= form_for @user, :url => yield(:url) do |f| %>
...
<% end %>
编辑.html.erb
<% provide(:title, 'Edit user') %>
<% provide(:button_text, 'Save changes') %>
<% provide(:url, edit_user_path(current_user)) %>
<h1>Update your profile</h1>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= render 'form' %>
<div class="gravatar_edit">
<%= gravatar_for @user %>
<a href="http://gravatar.com/emails" target="_blank">Change</a>
</div>
</div>
</div>
新的.html.erb
<% provide(:title, 'Sign up') %>
<% provide(:button_text, 'Create my account') %>
<% provide(:url, new_user_path) %>
<h1>Sign up</h1>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= render 'form' %>
</div>
</div>
我曾多次尝试让这个工作,尝试各种方法,但到目前为止,无济于事。这是失败的测试:
FAIL["test_invalid_signup_information", UsersSignupTest, 2.447965808212757]
test_invalid_signup_information#UsersSignupTest (2.45s)
Expected at least 1 element matching "form[action="/signup"]", found 0..
Expected 0 to be >= 1.
test/integration/users_signup_test.rb:8:in `block in <class:UsersSignupTest>'
及其代码:
test "invalid signup information" do
get signup_path
assert_response :success
assert_select "form[action=\"/signup\"]"
路线.rb
get '/signup', to: 'users#new'
post '/signup', to: 'users#create'
patch '/signup', to: 'users#update'
任何帮助将不胜感激!