用连接表搜索,ruby on rails

时间:2012-10-22 04:02:57

标签: ruby-on-rails-3 search

我有一个关于搜索代码表报销的问题,并在表用户中通过用户名输入。 这是形式搜索:

<%= 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>

1 个答案:

答案 0 :(得分:0)

除非您发布模型,否则很难判断,但假设用户有一个指向报销的关联,您可以这样做:

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