通过使用 Rails 匹配两列从数据库中获取行值 3

Getting row value from DB by matching two column using Rails 3

我有一个 table 像下面的结构。

table姓名users

id  Receipt_No   type   v_amount    v_date      c_date      v_name    v_status

7    150325006   SWD     60.00     2015-04-15  2015-04-28   Deepak    No

8    150325006   GOODS   1195.00   2015-04-15  2015-04-28   Deepak    No

9    150325006   BURNING  290.00   2015-04-15  2015-04-28  Deep       No

10   150325006   BURNING  290.00   2015-04-15   2015-04-15  Deep      No

我只知道 v_catagory 和 v_name 列 value.Suppose 我有 v_catagory="Deep" and v_name="BURNING" information.I 需要 v_name ="Deep" and v_catagory="BURNING" 的所有行值并最终显示table 中的所有必需值意味着 id no-9.10 应该显示在 table.Please 中帮助我。

你可以试试where方法(假设你的型号是User)。

在你的 *_controller.rb:

@result = User.where(type: 'BURNING', v_name: 'Deep')

在您看来:

<table>
  <% @result.each do |r| %>
     <tr>
        <th class="text-center"><%= check_box_tag :check_value, 1, :id => "checkbox1-1" %></th>
        <td class="text-center"><%= r.id %></td>
     </tr>
  <% end %>
</table>

原始 sql:

select * 
from users
where type = 'BURNING' and v_name = 'Deep'