在视图中分解嵌入式ruby代码(MVC)

时间:2016-09-27 17:23:29

标签: html ruby model-view-controller ruby-on-rails-5 embedded-ruby

我在做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 %>

edit.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>

new.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\"]"

的routes.rb

  get     '/signup',  to: 'users#new'
  post    '/signup',  to: 'users#create'
  patch   '/signup',  to: 'users#update'

非常感谢任何帮助!

0 个答案:

没有答案