我在视图上有这个代码,
<%=form_tag( '/price_verifications', method: "get", class: 'panel-body') do %>
<div class="form-group">
<%=select_tag :location, options_from_collection_for_select(Location.active_towns, :id, :name), prompt: "Select Location", class: 'form-control select2' %>
</div>
<div class="form-group">
<%=submit_tag "Filter", disable_with: 'Filtering...', class: 'btn btn-block btn-default' %>
</div>
<% end %>
当我选择其中一个位置并单击过滤器时,我想将选定的位置ID(例如44)传递给我的控制器:
def index
@missing_prices = Price.all_missing_prices(:id)
end
我的模特:
def self.all_missing_prices(id)
missing_prices = Product.find_by_sql("
SELECT *
FROM products
WHERE status = 1
AND id NOT IN (
SELECT product_id
FROM prices
WHERE CAST(created_at as date) = CAST(curdate() as date)
AND location_id = "+id.to_s+"
)
")
end
当我在控制器中硬编码44作为参数时,它就像魅力一样。
答案 0 :(得分:1)
您可以访问控制器中的位置值,如下所示
for (var i = 1; i < 101; i++) {
if(i % 3 == 0){
$("#main").append("divisible by 3");
}
else{
$("#main").append(i + '<br />');
}
}