所以我有用户和兴趣,他们通过interests_users表与has_and_belongs_to_many关系相关联。我想做的是让用户在通过复选框创建帐户时选择5个兴趣,但我现在不知道如何以相同的形式提交相同的参数5次,我目前正在提交复选框,但兴趣是不是布尔值。现在的代码是这样的:
<div class = "field">
<%= f.label :interests %><br>
<% all_interests = Interest.all.map{ |f| [f.name, f.id] } %>
<% all_interests.each do |interest| %>
<p> <%= interest[0] %> <%= f.check_box :interests %> <p>
<% end %>
</div>
答案 0 :(得分:2)
在视图中使用流动的
<% for interest in Interest.all %>
<%= check_box_tag "user[interest_ids][]", interest.id, @user.interests.include?(interest) %>
<%= interest.name %>
<% end %>
在控制器中接受params如下
params.require(:user).permit( { interest_ids:[] })
答案 1 :(得分:0)
您应该尝试以下代码:
SELECT
dmd.type,
dmd.locstatus,
ISNULL(det.Count, 0) Count,
ISNULL(det.balance,0) balance
FROM dmd
LEFT JOIN
(
SELECT d.type, d.locstatus, COUNT(cust.no_) AS Count, SUM(d.balance)
FROM dmd d
INNER JOIN cust ON d.rowno_custdmd_cust = cust.rowno
GROUP BY d.type, d.locstatus
) det
ON dmd.type = det.type
AND dmd.locstatus = det.locstatus
WHERE (dmd.type LIKE 'loc%')
ORDER BY dmd.type, dmd.locstatus