すべてがローカルホストで機能しているにもかかわらず、この奇妙なエラーが発生し続けます。
1) User pages profile page
Failure/Error: before { visit user_path(user) }
ActionView::Template::Error:
undefined method `model_name' for NilClass:Class
# ./app/views/shared/_create_list.html.erb:2:in `_app_views_shared__create_list_html_erb__3760252191913263716_70266394394440'
# ./app/views/users/show.html.erb:17:in `_app_views_users_show_html_erb__4038196524711190952_70266368588040'
# ./spec/requests/user_pages_spec.rb:12:in `block (3 levels) in <top (required)>'
ユーザーコントローラー
class UsersController < ApplicationController
before_filter :signed_in_user, only: [:edit, :update]
before_filter :correct_user, only: [:edit, :update]
def show
@user = User.find(params[:id])
@lists = @user.lists
@list = current_user.lists.build if signed_in?
end
リストコントローラー
class ListsController < ApplicationController
before_filter :signed_in_user
def create
@list = current_user.lists.build(params[:list])
if @list.save
flash[:success] = "List created!"
redirect_to current_user
else
redirect_to current_user
end
end
_create_list パーシャル
<div class="white-box">
<%= form_for(@list) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<div class="field">
<%= f.text_field :name, placeholder: "Create new list..." %>
<%= f.submit "Create list", class: "btn btn-primary" %>
</div>
<% end %>
</div>
ユーザー/番組
<div class="span8">
<% if @user.lists.any? %>
<h3>Lists (<%= @user.lists.count %>)</h3>
<ol class="lists">
<%= render @lists %>
</ol>
<% end %>
<%= render 'shared/create_list' %>
</div>
user_pages_spec
require 'spec_helper'
describe "User pages" do
subject { page }
describe "profile page" do
let(:user) { FactoryGirl.create(:user) }
let!(:m1) { FactoryGirl.create(:list, user: user, name: "Foo") }
let!(:m2) { FactoryGirl.create(:list, user: user, name: "Bar") }
before { visit user_path(user) }
私はレールに非常に慣れていないので、このエラーは何日も私を悩ませてきました! どんな提案でも大歓迎です!