私は、サイト上で失敗したテスト(正確には21件)/エラーメッセージを取得しています。ユーザー#でActiveRecord :: StatementInvalid in Users#show Railsチュートリアル第12章
のActiveRecord :: StatementInvalid示し
表示rails_projects/sample_app /アプリ/ビュー/共有/ _stats.html.erbライン#11が提起場所:ここ
また、「抽出したs 「また
8: </span> </a>
9: </td> <td>
10: <a href="<%= followers_user_path(@user) %>"> <span id="followers" class="stat">
11: <%= pluralize(@user.followers.count, "follower") %> </span>
12: </a> </td>
13: </tr>
14: </table>
Trace of template inclusion: app/views/users/show.html.erb
:
app/views/shared/_stats.html.erb:11:in `_app_views_shared__stats_html_erb__1272198506242050260_70324836955760_711623751783882131'
app/views/users/show.html.erb:22:in `_app_views_users_show_html_erb___2566196705224179076_70324816563400__997253365199883939'
私は
<%= pluralize(@user.followers.count, "follower") %>
ラインを奪う、サイトの作品(と私の失敗のテストは6に縮小ource(ライン#11の周囲) )。
失敗したテストでも、同様のSQLエラーが発生しているようです。ここで失敗するテストです:
ここrspec ./spec/controllers/users_controller_spec.rb:313 # UsersController DELETE 'destroy' as an admin user should destroy the user
rspec ./spec/controllers/users_controller_spec.rb:319 # UsersController DELETE 'destroy' as an admin user should redirect to the users page
rspec ./spec/controllers/users_controller_spec.rb:355 # UsersController follow pages when signed in should show user followers
rspec ./spec/models/user_spec.rb:185 # User micropost associations should destroy associated microposts
rspec ./spec/models/user_spec.rb:265 # User relationships should include the follower in the followers array
は、彼らが得ることを(それぞれ)エラーです:ここでは
1. Failure/Error: delete :destroy, :id => @user
ActiveRecord::StatementInvalid:
SQLite3::SQLException: near "id": syntax error: SELECT "relationships".* FROM "relationships" WHERE ("relationships".followed_ id = 1)
2. Failure/Error: delete :destroy, :id => @user
ActiveRecord::StatementInvalid:
SQLite3::SQLException: near "id": syntax error: SELECT "relationships".* FROM "relationships" WHERE ("relationships".followed_ id = 1)
3. Failure/Error: get :followers, :id => @other_user
ActiveRecord::StatementInvalid:
SQLite3::SQLException: near "id": syntax error: SELECT "users".* FROM "users" INNER JOIN "relationships" ON "users".id = "relationships".follower_id WHERE (("relationships".followed_ id = 2)) LIMIT 30 OFFSET 0
4. Failure/Error: @user.destroy
ActiveRecord::StatementInvalid:
SQLite3::SQLException: near "id": syntax error: SELECT "relationships".* FROM "relationships" WHERE ("relationships".followed_ id = 1)
5. Failure/Error: @followed.followers.should include(@user)
ActiveRecord::StatementInvalid:
SQLite3::SQLException: near "id": syntax error: SELECT "users".* FROM "users" INNER JOIN "relationships" ON "users".id = "relationships".follower_id WHERE (("relationships".followed_ id = 2))
は私の "_stats.html.erb" ファイルです:
<% @user ||= current_user %> <div class="stats">
<table summary="User stats">
<tr>
<td>
<a href="<%= following_user_path(@user) %>">
<span id="following" class="stat">
<%= @user.following.count %> following
</span>
</a>
</td>
<td>
<a href="<%= followers_user_path(@user) %>">
<span id="followers" class="stat">
<%= pluralize(@user.followers.count, "follower") %>
</span>
</a>
</td>
</tr>
</table>
私の "show.html.erb"ファイルは次のとおりです。
ここ<table summary="Information about following/followers">
<tr>
<td class="main">
<h1><%= @title %></h1>
<% unless @users.empty? %>
<ul class="users">
<%= render @users %>
</ul>
<%= will_paginate @users %>
<% end %>
</td>
<td class="sidebar round">
<strong>Name</strong> <%= @user.name %><br/>
<strong>URL</strong> <%= link_to user_path(@user), @user %><br/>
<strong>Microposts</strong> <%= @user.microposts.count%>
<%= render 'shared/stats' %>
<% unless @users.empty? %>
<% @users.each do |user| %>
<%= link_to gravatar_for(user, :size => 30), user%>
<% end %>
<% end %>
</td>
</tr>
(それは場合に役立ちます)、私の関係のDBファイルです:
class CreateRelationships < ActiveRecord::Migration
def self.up
create_table :relationships do |t|
t.integer :follower_id
t.integer :followed_id
t.timestamps
end
add_index :relationships, :follower_id
add_index :relationships, :followed_id
add_index :relationships, [:follower_id, :followed_id], :unique => true
end
def self.down
drop_table :relationships
end
end
私は、マイグレーションを削除して、もう一度やり直す(また、テスト・データベースを準備する)試したが、それでも何も。
私が問題を解決するために提供しなければならない他のファイルがある場合は、教えてください!
EDIT
問題はここに私のUserモデルでした。 「
class User < ActiveRecord::Base
attr_accessor :password
attr_accessible :name, :email, :password, :password_confirmation
has_many :microposts, :dependent => :destroy
has_many :relationships, :foreign_key => "follower_id",
:dependent => :destroy
has_many :following, :through => :relationships, :source => :followed
has_many :reverse_relationships, :foreign_key => **"followed_id"**,
:class_name => "Relationship",
:dependent => :destroy
has_many :followers, :through => :reverse_relationships, :source => :follower
FOREIGN_KEYが「followed_ ID」
あなたは正しいです!問題は私のUserモデルにありました。ありがとう! – Angel