Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 使用rubyonrails中的join通过文本框从多个表获取数据_Ruby On Rails - Fatal编程技术网

Ruby on rails 使用rubyonrails中的join通过文本框从多个表获取数据

Ruby on rails 使用rubyonrails中的join通过文本框从多个表获取数据,ruby-on-rails,Ruby On Rails,在我的搜索页面中,我有两个文本框,“tf_-Zip”和“tf_-Designation”,在其中输入“Zip”和用户名称,我有两个模型,即: user's model id | name | user_Zip 1 | abc | 10005 2 | mno | 10005 3 | xyz | 10005 profession's model id | UserID | Designation 1 | 1 | Lead 2 | 2 | software en

在我的搜索页面中,我有两个文本框,“tf_-Zip”和“tf_-Designation”,在其中输入“Zip”和用户名称,我有两个模型,即:

user's model 
id | name | user_Zip
1  | abc  | 10005
2  | mno  | 10005
3  | xyz  | 10005

profession's model
id | UserID | Designation
1  | 1      | Lead
2  | 2      | software engineer
3  | 3      | Lead
我希望当我在tf_Zip文本框中输入
user_Zip,即10005,在tf_Designation文本框中输入Designation,即Lead,然后它会给出那些user_Zip为10005,Designation=Lead的用户,user 1和user 3是那些user_Zip为10005,Designation=Lead的用户,我使用以下代码:

def search
@user_zipdesignation = Profession.joins(:user).where('users.user_Zip' => params[:tf_Zip] 'and professions.Designation' => params[:tf_Designation])
end
在代码中,我使用了两个条件作为用户_Zip和指定,但它给了我以下错误:

C:/Sites/MentorMentored1/app/controllers/search_controller.rb:32: syntax error, unexpected tSTRING_BEG, expecting ')' ....user_Zip' => params[:tf_Zip] 'and professions.Designation' ... ... ^ C:/Sites/MentorMentored1/app/controllers/search_controller.rb:32: syntax error, unexpected tASSOC, expecting keyword_end ...and professions.Designation' => params[:tf_Designation]) ... ^ C:/Sites/MentorMentored1/app/controllers/search_controller.rb:32: syntax error, unexpected ')', expecting keyword_end C:/Sites/MentorMentored1/app/controllers/search_controller.rb:50: syntax error, unexpected $end, expecting keyword_end
我不明白我错过了什么。请帮助我,等待答复。谢谢这行吗

def search
  @user_zipdesignation = Profession.joins(:user).where('users.user_Zip' => params[:tf_Zip],  'professions.Designation' => params[:tf_Designation])
end
试试看

def search
  @user_zipdesignation = Profession.joins(:user).where('users.user_Zip = ? AND professions.Designation= ?',params[:tf_Zip],params[:tf_Designation])
end

并查看开发日志中的SQl语句

no它不起作用,因为它只检查用户条件,并且应该同时检查这两个条件。