다음과 같은 트위터와 유사한 모델을 설정했습니다. 사용자는 모두 서로 구독 할 수 있습니다. 관계를 만들려고 할 때 내 사용자 컨트롤러에 오류가 발생합니다.다자간 연결이 실패하는 이유는 무엇입니까?
user.rb :
has_many :subscriptions
has_many :providers, :through => :subscriptions
has_many :followings, :class_name => "Subscription"
has_many :followers, :through => :followings
subscription.rb
belongs_to :provider, :class_name => 'User', :foreign_key => "provider_id"
belongs_to :follower, :class_name => 'User', :foreign_key => "follower_id"
users_controller.rb
69 def follow
70 logger.debug params.to_yaml
71 @user = User.find(params["user_id"])
72 logger.debug @user.to_yaml
73 if current_user.providers << @user
74 flash[:notice] = "Subscribed"
75 else
76 flash[:error] = "Unable to subscribe."
77 end
78 end
내가 전화 할 때 이것은 다음과 오류입니다 :
ActiveRecord::UnknownAttributeError (unknown attribute: user_id):
app/controllers/users_controller.rb:73:in `follow'
,536,
rake db : migrate를 실행했음을 확인했습니다. subscription 테이블에는 provider_id와 follower_id 두 개의 필드가 있습니다. 누구든지 오류를 도와 줄 수 있고 'user_id'속성을 찾는 이유를 설명 할 수 있습니까?
업데이트 :
show.html.erb :
<%= button_to "Subscribe", user_follow_path(@user), :remote => true %>
routes.rb :
resources :users do
resources :locations
resources :saved_events
resources :saved_locations
post "follow"
end
레이크 노선 | 그렙 추적 : 당신이 제공 컬렉션 <<
를 호출 할 때 사용자가이 추종자해야하는데 모르기 때문에
user_follow POST /users/:user_id/follow(.:format) {:action=>"follow", :controller=>"users"}
당신이 코드에서 users_controller.b에서 라인 73에 주석을 달 수 있습니까? – klochner