我想获取张贴谁去了同一所大学作为当前用户的这些用户的所有帖子......所以我欢迎控制器里面我写了下面的代码..如何在控制器内使用行动数组变量
class WelcomesController < ApplicationController
def index
@col = Education.select(:college_id).where(:user_id => @current_user)
@user = Education.select(:user_id).where(:college_id => @col)
@welcome = Welcome.where(:user_id => @user)
end
end
以下为欢迎和教育模式我的玛代码:
create_table "welcomes", :force => true do |t|
t.text "message"
t.integer "user_id"
end
create_table "educations", :force => true do |t|
t.integer "college_id"
t.integer "user_id"
end
@col = Education.select(:college_id).where(:user_id => @current_user)
.... 此行返回与当前登录的user.This相关高校IDS是我的控制台被返回下面的输出上可以正常使用..
[#<Education college_id: 1>, #<Education college_id: 2>]
但我不知道如何在我的下一行使用这个输出,所以我写了这个声明,它应该返回所有用户的大学ID是prevous语句的输出
@user = Education.select(:user_id).where(:college_id => @col)
和我的最后一行应该返回发表其ID是@user阵列内的用户的所有帖子:
@welcome = Welcome.where(:user_id => @user)
但这不是working.When我跑我的项目,我看不到我的网页和控制台上的任何输出我越来越接着输出: SELECT welcomes
。* FROM welcomes
WHERE(welcomes
。 user_id
IN(NULL)) 这意味着它没有得到任何的用户ID .. 我怎么能解决这个...
**使用粗体文本会使事情变得更难以阅读,并且不知道什么是重要的,所以请避免使用粗体文本处理长句,而是使用粗体文本强调真正需要强调的内容。 ** – Zabba 2012-04-09 06:33:04
好吧Zabba会照顾你说的... – NJF 2012-04-09 07:31:44