I'm going through the railstutorial.org book, and after adding a micropost instance variable at app/controllers/pages_controller.rb, my app's homepage fails to render and instead gives me the following error (on the browser):
ActionView::MissingTemplate in Pages#home
Showing /app/views/pages/home.html.erb where line #9 raised:
Missing partial shared/user_info with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:html], :locale=>[:en, :en]} in view paths "/app/views"
Extracted source (around line #9):
6: <%= render 'shared/micropost_form' %>
7: </td>
8: <td class="sidebar round">
9: <%= render 'shared/user_info' %>
10: </td>
11: </tr>
12: </table>
Rails.root: /home/panos/sites/sample_app
Application Trace | Framework Trace | Full Trace
app/views/pages/home.html.erb:9:in `_app_views_pages_home_html_erb__134372853_79989310__180950044'
Rspec gives me the following errors:
Failures:
1) MicropostsController POST 'create' failure should not create a micropost
Failure/Error: post :create, :micropost => @attr
ActionView::Template::Error:
Missing partial shared/user_info with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:html], :locale=>[:en, :en]} in view paths "/home/panos/sites/sample_app/app/views"
# ./app/views/pages/home.html.erb:9:in `_app_views_pages_home_html_erb__186087139_72921610__1052842684'
# ./app/controllers/microposts_controller.rb:10:in `create'
# ./spec/controllers/microposts_controller_spec.rb:33:in `block (5 levels) in <top (required)>'
# ./spec/controllers/microposts_controller_spec.rb:32:in `block (4 levels) in <top (required)>'
2) MicropostsController POST 'create' failure should render the home page
Failure/Error: post :create, :micropost => @attr
ActionView::Template::Error:
Missing partial shared/user_info with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:html], :locale=>[:en, :en]} in view paths "/home/panos/sites/sample_app/app/views"
# ./app/views/pages/home.html.erb:9:in `_app_views_pages_home_html_erb__186087139_72921610__1052842684'
# ./app/controllers/microposts_controller.rb:10:in `create'
# ./spec/controllers/microposts_controller_spec.rb:38:in `block (4 levels) in <top (required)>'
3) UsersController GET 'new' should be successful
Failure/Error: get :new
ActionView::Template::Error:
undefined local variable or method `object' for #<#<Class:0xa89d8ac>:0xaa3a174>
# ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb__638819034_88046780__702891636'
# ./app/views/users/new.html.erb:4:in `block in _app_views_users_new_html_erb__995846824_89246620__1052842684'
# ./app/views/users/new.html.erb:3:in `_app_views_users_new_html_erb__995846824_89246620__1052842684'
# ./spec/controllers/users_controller_spec.rb:102:in `block (3 levels) in <top (required)>'
4) UsersController GET 'new' should have the right title
Failure/Error: get :new
ActionView::Template::Error:
undefined local variable or method `object' for #<#<Class:0xa89d8ac>:0xaa08ae8>
# ./app/views/shared/开发者_开发问答_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb__638819034_88046780__702891636'
# ./app/views/users/new.html.erb:4:in `block in _app_views_users_new_html_erb__995846824_89246620__1052842684'
# ./app/views/users/new.html.erb:3:in `_app_views_users_new_html_erb__995846824_89246620__1052842684'
# ./spec/controllers/users_controller_spec.rb:107:in `block (3 levels) in <top (required)>'
5) UsersController 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:0xa89d8ac>:0xa99271c>
# ./app/views/shared/_error_messages.html.erb:1:in `_app_views_shared__error_messages_html_erb__638819034_88046780__702891636'
# ./app/views/users/new.html.erb:4:in `block in _app_views_users_new_html_erb__995846824_89246620__1052842684'
# ./app/views/users/new.html.erb:3:in `_app_views_users_new_html_erb__995846824_89246620__1052842684'
# ./app/controllers/users_controller.rb:30:in `create'
# ./spec/controllers/users_controller_spec.rb:122:in `block (5 levels) in <top (required)>'
# ./spec/controllers/users_controller_spec.rb:121:in `block (4 levels) in <top (required)>'
Here is my home.html.erb file:
<% if signed_in? %>
<table class="front" summary="For signed-in users">
<tr>
<td class="main">
<h1 class="micropost">What's up?</h1>
<%= render 'shared/micropost_form' %>
</td>
<td class="sidebar round">
<%= render 'shared/user_info' %>
</td>
</tr>
</table>
<% else %>
<h1>Sample App</h1>
<p>
This is the home page for the
<a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
sample application.
</p>
<%= link_to "Sign up now!", signup_path, :class => "signup_button round" %>
<% end %>
And here is my _user_info.html.erb file:
<div class="user_info">
<a href="<%= user_path(current_user) %>">
<%= gravatar_for current_user, :size => 30 %>
<span class="user_name">
<%= current_user.name %>
</span>
<span class="microposts">
<%= pluralize(current_user.microposts.count, "micropost") %>
</span>
</a>
</div>
I dont think I've made a mistake in following the tutorial. I've even looked through similar threads stackoverflow.com threads, to no avail:
NoMethodError in Pages#home
ruby on rails tutorial - rails 3.0 chapter 11 rspec fails after code listing 11.27
Does anyone have any ideas?
It is missing the following code at app/views/shared/_user_info.html.erb
<div class="user_info">
<a href="<%= user_path(current_user) %>">
<%= gravatar_for current_user, :size => 30 %>
<span class="user_name">
<%= current_user.name %>
</span>
<span class="microposts">
<%= pluralize(current_user.microposts.count, "micropost") %>
</span>
</a>
</div>
You need to add view app/views/shared/_user_info.html.erb
.
I guess you have wrong path for it.
it is looks like you does not passed step are showed in Listing 11.30:
def home
@title = "Home"
@micropost = Micropost.new if signed_in?
end
but I have no clue why it reflected on render user_info partial :(
精彩评论