Reputation: 497
I have almost completed this tutorial when I started to get these error messages. Can someone give me a starting point on where to begin find out whats wrong. What files do you all need to see?
Failures:
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
This is _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 %>
This my _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%>
This is _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>
Upvotes: 0
Views: 586
Reputation: 1
I think you need to go to the file that is calling the _error_messages partial and simply make sure you're calling it using the following:
<%= render 'shared/error_messages', object: f.object %>
This is because you're adding the hidden field tag.
Upvotes: 0
Reputation: 37
I had this issue as well, to fix it I didn't adjust the code from Michael's example, I just moved the _fields.html.erb
partial from the views/users
folder to the views/shared
folder. Once in the shared folder it seemed to accept objects from both controllers. Hope this helps.
Upvotes: 0
Reputation: 1
This is still an issue in the latest version of the book as of this posting.
Earlier in the book the fields for user related forms were refactored and put in a partial _fields.html.erb
where the shared/error_messages
was rendered.
The users/new
and users/edit
files don't need to be modified, as stated in the book, and instead the only part that needs to be modified is _fields.html.erb
to pass object: f.object
to shared/error_messages
Upvotes: 0
Reputation: 3947
Errors 2 through 15 have a simple fix: your _fields.html.erb is missing some code on the first line. The entire line should read:
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.
Unfortunately I can't do anything with the rest of your errors since your relevant code isn't attached.
Upvotes: 1