2012-10-22 4 views
0

코드 테이블 상환 검색에 대한 질문이 있으며 사용자가 테이블 사용자로 입력했습니다. 이 형태의 검색입니다 :조인 테이블, 루비 레일로 검색

<%= form_tag reimburses_searchreimburse_path, method: :get do %> 
        <%= text_field_tag :reimburse, params[:reimburse] %> 
        <%= submit_tag "Search", name: nil%> 
        <% end %> 

def searchreimburse 
@users = User.where("username LIKE ? ", "%#{params[:reimburse]}%") 
@reimburses = Reimburse.all 
@project = Project.all 
end 

내가 원하는이 컨트롤러 같은 출력 :

<tr>      
        <th >#</th> 
        <th >Date</th> 
        <th >Project name</th> 
        <th >Title</th> 
        <th >User name</th> #*this from table user* 
        <th >Status</th> 
        <th >Action</th> 
       </tr> 
+0

무엇이 문제입니까? – ryudice

답변

0

당신이 당신의 모델을 게시하지 않는 말할 어렵지만, 사용자를 가정 당신이 이것을 할 수있는 환급을 가리키는 협회가 있습니다 :

@reimburses = @users.map(&:reimburses).flatten 
+0

예, 사용자 모델 has_many 상환 및 reimburses 모델 belongs_to 사용자 – Arif