Nic T.
Nic T.

Reputation: 11

Running into error in the Micheal Hartl Ruby on Rails Tutorial section 10.1.1

A noob question here; Not sure why I am getting this error, have been following the ruby tutorial to a 'T' I thought, here is my error:

FAIL["test_invalid_signup_information", UsersSignupTest, 1.276558378001937] test_invalid_signup_information#UsersSignupTest (1.28s) Expected at least 1 element matching "form[action="/signup"]", found 0.. Expected 0 to be >= 1. test/integration/users_signup_test.rb:7:in `block in '

and here is the test that it's referring to:

test "invalid signup information" do
    get signup_path
    assert_select 'form[action="/signup"]'

    assert_no_difference 'User.count' do
        post signup_path, params: { user: {name: "", email: "user@invalid", password: "foo", password_confirmation: "bar"}}
    end

is this a routing issue? I honestly went back and redid the entire previous chapter and still can't find my slip up, any ideas what I am missing?

edit: Here is the partial it is referring to, _form.html.erb:

<%= form_for(@user) do |f| %>
 <%= render 'shared/error_messages', object: @user %>

 <%= f.label :name %>
 <%= f.text_field :name, class: 'form-control' %>

 <%= f.label :email %>
 <%= f.email_field :email, class: 'form-control' %>

 <%= f.label :password %>
 <%= f.password_field :password, class: 'form-control' %>

 <%= f.label :password_confirmation %>
 <%= f.password_field :password_confirmation, class: 'form-control' %>

 <%= f.submit yield(:button_text), class: "btn btn-primary" %>
<% end %>

Upvotes: 1

Views: 427

Answers (1)

Shishir Pande
Shishir Pande

Reputation: 11

I'm working on the same tutorial and came across the same issue. The problem you are having is due to the fact that you completed the previous exercise in 7.3.4. This section had you update the form such that it posted to the correct URL.

You will have to update line 1 of your partial _form.html.erb to the following:

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

This should eliminate the error.

Edit: You will have to use a yield for the url above as the path is different for the 2 uses of the form. i.e.: edit: need right parenthesis

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

This requires a new provide line in both the edit.html.erb:

<% provide(:form_path, user_path) %>

and the new.html.erb files:

<% provide(:form_path, signup_path) %>

Upvotes: 1

Related Questions