0

これらのエラー メッセージが表示され始めた時点で、このチュートリアルはほぼ完了しています。どこが悪いのかを見つけるための出発点を誰かに教えてもらえますか。どのファイルを見る必要がありますか?

失敗:

  1) MicropostsController DELETE 'destroy'  for an unauthorized user should deny access
     Failure/Error: response.should redirect_to(root_path)
       Expected response to be a redirect to <http://test.host/> but was a redirect to <http://test.host/signin>
     # ./spec/controllers/microposts_controller_spec.rb:72:in `block (4 levels) in <top (required)>'

  2) UsersController GET 'new' should be successful
     Failure/Error: get :new
     ActionView::Template::Error:
       undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x00000005a62f70>
     # ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
     # ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
     # ./app/views/users/new.html.erb:7:in `block in _app_views_users_new_html_erb___2634588673674572576_47386100'
     # ./app/views/users/new.html.erb:3:in `_app_views_users_new_html_erb___2634588673674572576_47386100'
     # ./spec/controllers/users_controller_spec.rb:131:in `block (3 levels) in <top (required)>'

  3) UsersController GET 'new' should have the right title
     Failure/Error: get :new
     ActionView::Template::Error:
       undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x00000004242df0>
     # ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
     # ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
     # ./app/views/users/new.html.erb:7:in `block in _app_views_users_new_html_erb___2634588673674572576_47386100'
     # ./app/views/users/new.html.erb:3:in `_app_views_users_new_html_erb___2634588673674572576_47386100'
     # ./spec/controllers/users_controller_spec.rb:136:in `block (3 levels) in <top (required)>'

  4) UsersController GET 'new' POST 'create' failure  should have the right title
     Failure/Error: post :create, :user => @attr
     ActionView::Template::Error:
       undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x00000004c96518>
     # ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
     # ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
     # ./app/views/users/new.html.erb:7:in `block in _app_views_users_new_html_erb___2634588673674572576_47386100'
     # ./app/views/users/new.html.erb:3:in `_app_views_users_new_html_erb___2634588673674572576_47386100'
     # ./app/controllers/users_controller.rb:29:in `create'
     # ./spec/controllers/users_controller_spec.rb:148:in `block (5 levels) in <top (required)>'

  5) UsersController GET 'new' POST 'create' failure  should render the 'new' page
     Failure/Error: post :create, :user => @attr
     ActionView::Template::Error:
       undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x000000056482c8>
     # ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
     # ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
     # ./app/views/users/new.html.erb:7:in `block in _app_views_users_new_html_erb___2634588673674572576_47386100'
     # ./app/views/users/new.html.erb:3:in `_app_views_users_new_html_erb___2634588673674572576_47386100'
     # ./app/controllers/users_controller.rb:29:in `create'
     # ./spec/controllers/users_controller_spec.rb:152:in `block (5 levels) in <top (required)>'

  6) UsersController GET 'new' POST 'create' failure  should not create a user
     Failure/Error: post :create, :user => @attr
     ActionView::Template::Error:
       undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x000000051f8038>
     # ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
     # ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
     # ./app/views/users/new.html.erb:7:in `block in _app_views_users_new_html_erb___2634588673674572576_47386100'
     # ./app/views/users/new.html.erb:3:in `_app_views_users_new_html_erb___2634588673674572576_47386100'
     # ./app/controllers/users_controller.rb:29:in `create'
     # ./spec/controllers/users_controller_spec.rb:157:in `block (6 levels) in <top (required)>'
     # ./spec/controllers/users_controller_spec.rb:156:in `block (5 levels) in <top (required)>'

  7) UsersController GET 'new' GET 'edit' should be succesful
     Failure/Error: get :edit, :id => @user
     ActionView::Template::Error:
       undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x000000053301f8>
     # ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
     # ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
     # ./app/views/users/edit.html.erb:5:in `block in _app_views_users_edit_html_erb___4049085790763719618_40974080'
     # ./app/views/users/edit.html.erb:3:in `_app_views_users_edit_html_erb___4049085790763719618_40974080'
     # ./spec/controllers/users_controller_spec.rb:197:in `block (4 levels) in <top (required)>'

  8) UsersController GET 'new' GET 'edit' should have the right title
     Failure/Error: get :edit, :id => @user
     ActionView::Template::Error:
       undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x0000000508af20>
     # ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
     # ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
     # ./app/views/users/edit.html.erb:5:in `block in _app_views_users_edit_html_erb___4049085790763719618_40974080'
     # ./app/views/users/edit.html.erb:3:in `_app_views_users_edit_html_erb___4049085790763719618_40974080'
     # ./spec/controllers/users_controller_spec.rb:202:in `block (4 levels) in <top (required)>'

  9) UsersController GET 'new' GET 'edit' should have a link to change the gravatar
     Failure/Error: get :edit, :id => @user
     ActionView::Template::Error:
       undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x000000059d7d08>
     # ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
     # ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
     # ./app/views/users/edit.html.erb:5:in `block in _app_views_users_edit_html_erb___4049085790763719618_40974080'
     # ./app/views/users/edit.html.erb:3:in `_app_views_users_edit_html_erb___4049085790763719618_40974080'
     # ./spec/controllers/users_controller_spec.rb:207:in `block (4 levels) in <top (required)>'

  10) UsersController GET 'new' PUT 'update' should change the user's attributes
     Failure/Error: put :update, :id => @user, :user => @attr
     ActionView::Template::Error:
       undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x00000004cf6990>
     # ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
     # ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
     # ./app/views/users/edit.html.erb:5:in `block in _app_views_users_edit_html_erb___4049085790763719618_40974080'
     # ./app/views/users/edit.html.erb:3:in `_app_views_users_edit_html_erb___4049085790763719618_40974080'
     # ./app/controllers/users_controller.rb:43:in `update'
     # ./spec/controllers/users_controller_spec.rb:247:in `block (4 levels) in <top (required)>'

  11) UsersController GET 'new' PUT 'update' should have the right title
     Failure/Error: put :update, :id => @user, :user => @attr
     ActionView::Template::Error:
       undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x000000054200b8>
     # ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
     # ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
     # ./app/views/users/edit.html.erb:5:in `block in _app_views_users_edit_html_erb___4049085790763719618_40974080'
     # ./app/views/users/edit.html.erb:3:in `_app_views_users_edit_html_erb___4049085790763719618_40974080'
     # ./app/controllers/users_controller.rb:43:in `update'
     # ./spec/controllers/users_controller_spec.rb:255:in `block (4 levels) in <top (required)>'

  12) UsersController GET 'new' PUT 'update' failure should render the 'edit' page
     Failure/Error: put :update, :id => @user, :user => @attr
     ActionView::Template::Error:
       undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x000000057c0448>
     # ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
     # ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
     # ./app/views/users/edit.html.erb:5:in `block in _app_views_users_edit_html_erb___4049085790763719618_40974080'
     # ./app/views/users/edit.html.erb:3:in `_app_views_users_edit_html_erb___4049085790763719618_40974080'
     # ./app/controllers/users_controller.rb:43:in `update'
     # ./spec/controllers/users_controller_spec.rb:231:in `block (5 levels) in <top (required)>'

  13) FriendlyForwardings should forward to the requested page after signin
     Failure/Error: click_button
     ActionView::Template::Error:
       undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x0000000541df48>
     # ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
     # ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
     # ./app/views/users/edit.html.erb:5:in `block in _app_views_users_edit_html_erb___4049085790763719618_40974080'
     # ./app/views/users/edit.html.erb:3:in `_app_views_users_edit_html_erb___4049085790763719618_40974080'
     # ./spec/requests/friendly_forwardings_spec.rb:10:in `block (2 levels) in <top (required)>'

  14) LayoutLinks should have an signup page at '/signup'
     Failure/Error: get '/signup'
     ActionView::Template::Error:
       undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x00000003980370>
     # ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
     # ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
     # ./app/views/users/new.html.erb:7:in `block in _app_views_users_new_html_erb___2634588673674572576_47386100'
     # ./app/views/users/new.html.erb:3:in `_app_views_users_new_html_erb___2634588673674572576_47386100'
     # ./spec/requests/layout_links_spec.rb:28:in `block (2 levels) in <top (required)>'

  15) LayoutLinks should have the right links on the layout
     Failure/Error: click_link "Sign up now!"
     ActionView::Template::Error:
       undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x000000058c3098>
     # ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
     # ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
     # ./app/views/users/new.html.erb:7:in `block in _app_views_users_new_html_erb___2634588673674572576_47386100'
     # ./app/views/users/new.html.erb:3:in `_app_views_users_new_html_erb___2634588673674572576_47386100'
     # ./spec/requests/layout_links_spec.rb:47:in `block (2 levels) in <top (required)>'

  16) creation  failure should not make a new micropost
     Failure/Error: fill_in :micropost_content, :with => ""
     Webrat::NotFoundError:
       Could not find field: :micropost_content
     # ./spec/requests/microposts_spec.rb:17:in `block (4 levels) in <top (required)>'
     # ./spec/requests/microposts_spec.rb:15:in `block (3 levels) in <top (required)>'

  17) creation  success should make a new micropost
     Failure/Error: fill_in :micropost_content, :with => content
     Webrat::NotFoundError:
       Could not find field: :micropost_content
     # ./spec/requests/microposts_spec.rb:30:in `block (4 levels) in <top (required)>'
     # ./spec/requests/microposts_spec.rb:28:in `block (3 levels) in <top (required)>'

  18) Users signup failure should not make a new user
     Failure/Error: visit signup_path
     ActionView::Template::Error:
       undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x00000005766c40>
     # ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
     # ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
     # ./app/views/users/new.html.erb:7:in `block in _app_views_users_new_html_erb___2634588673674572576_47386100'
     # ./app/views/users/new.html.erb:3:in `_app_views_users_new_html_erb___2634588673674572576_47386100'
     # ./spec/requests/users_spec.rb:11:in `block (5 levels) in <top (required)>'
     # ./spec/requests/users_spec.rb:10:in `block (4 levels) in <top (required)>'

  19) Users signup success should make a new
     Failure/Error: visit signup_path
     ActionView::Template::Error:
       undefined local variable or method `object' for #<#<Class:0x000000051d2680>:0x000000059e8bd0>
     # ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb___1348716384004617740_45632520'
     # ./app/views/users/_fields.html.erb:2:in `_app_views_users__fields_html_erb___3244409800155025389_45601120'
     # ./app/views/users/new.html.erb:7:in `block in _app_views_users_new_html_erb___2634588673674572576_47386100'
     # ./app/views/users/new.html.erb:3:in `_app_views_users_new_html_erb___2634588673674572576_47386100'
     # ./spec/requests/users_spec.rb:27:in `block (5 levels) in <top (required)>'
     # ./spec/requests/users_spec.rb:26:in `block (4 levels) in <top (required)>'

Finished in 4.31 seconds
124 examples, 19 failures

Failed examples:

rspec ./spec/controllers/microposts_controller_spec.rb:70 # MicropostsController DELETE 'destroy'  for an unauthorized user should deny access
rspec ./spec/controllers/users_controller_spec.rb:130 # UsersController GET 'new' should be successful
rspec ./spec/controllers/users_controller_spec.rb:135 # UsersController GET 'new' should have the right title
rspec ./spec/controllers/users_controller_spec.rb:147 # UsersController GET 'new' POST 'create' failure  should have the right title
rspec ./spec/controllers/users_controller_spec.rb:151 # UsersController GET 'new' POST 'create' failure  should render the 'new' page
rspec ./spec/controllers/users_controller_spec.rb:155 # UsersController GET 'new' POST 'create' failure  should not create a user
rspec ./spec/controllers/users_controller_spec.rb:196 # UsersController GET 'new' GET 'edit' should be succesful
rspec ./spec/controllers/users_controller_spec.rb:201 # UsersController GET 'new' GET 'edit' should have the right title
rspec ./spec/controllers/users_controller_spec.rb:206 # UsersController GET 'new' GET 'edit' should have a link to change the gravatar
rspec ./spec/controllers/users_controller_spec.rb:246 # UsersController GET 'new' PUT 'update' should change the user's attributes
rspec ./spec/controllers/users_controller_spec.rb:254 # UsersController GET 'new' PUT 'update' should have the right title
rspec ./spec/controllers/users_controller_spec.rb:230 # UsersController GET 'new' PUT 'update' failure should render the 'edit' page
rspec ./spec/requests/friendly_forwardings_spec.rb:4 # FriendlyForwardings should forward to the requested page after signin
rspec ./spec/requests/layout_links_spec.rb:27 # LayoutLinks should have an signup page at '/signup'
rspec ./spec/requests/layout_links_spec.rb:38 # LayoutLinks should have the right links on the layout
rspec ./spec/requests/microposts_spec.rb:14 # creation  failure should not make a new micropost
rspec ./spec/requests/microposts_spec.rb:26 # creation  success should make a new micropost
rspec ./spec/requests/users_spec.rb:8 # Users signup failure should not make a new user
rspec ./spec/requests/users_spec.rb:25 # Users signup success should make a new

# Finished at 2012-05-15 16:41:20

これは _error_messages.html.erb です

<% if object.errors.any? %>

    <div id="error_explanation">
        <h2>
            <%= pluralize(object.errors.count, "error") %>
          prohibited this <%= object.class.to_s.underscore.humanize.downcase %> from being saved:
            </h2>
            <p>There were problems with the following fields:</p>
                <ul>
                <% object.errors.full_messages.each do |message| %>

                <li><%= message %></li>
                <% end %>
                </ul>
            </div>
    <% end %>

これは私の _micropost_form.html.erb

<%= form_for(@micropost) do |f| %>


<%= render 'shared/error_messages', :object => f.object %>

<div class="field">
    <%= f.text_area  :content %>
    </div>
<div class="=actions">
    <%= f.submit "Submit" %>

    </div>
<%end%>

これは _fields.html.erb です

<%= render 'shared/error_messages'%>
<div class="field">
    <%= f.label :name %><br/>
    <%= f.text_field :name%>

</div>


<div class="field">
    <%= f.label :email %><br/>
    <%= f.text_field :email %>

</div>


<div class="field">
    <%= f.label :password %><br/>
    <%= f.password_field :password %>

</div>


<div class="field">
    <%= f.label :password_confirmation, "Confirmation" %><br/>
    <%= f.password_field :password_confirmation %>

</div>
4

4 に答える 4

1

エラー2から15には、簡単な修正があります。_fields.html.erbの最初の行にコードがありません。行全体は次のようになります。

app/views/layouts/_fields.html.erb   
<%= render 'shared/error_messages', object: f.object %> #object: f.object allows the form variable to 
                #access the associated object.

残念ながら、関連するコードが添付されていないため、残りのエラーについては何もできません。

于 2013-02-24T23:50:46.063 に答える
0

_error_messages パーシャルを呼び出しているファイルに移動し、次を使用して呼び出していることを確認する必要があると思います。

  <%= render 'shared/error_messages', object: f.object %>

これは、隠しフィールド タグを追加しているためです。

于 2014-11-30T21:56:02.150 に答える