我有一个关于搜索代码表报销的问题,并在表用户中通过用户名输入。 这是形式搜索:
<%= 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 :(得分:0)
除非您发布模型,否则很难判断,但假设用户有一个指向报销的关联,您可以这样做:
@reimburses = @users.map(&:reimburses).flatten