【发布时间】:2016-03-02 15:06:44
【问题描述】:
我正在使用 gem 'ransack' 来搜索记录。
我正在编程的页面仅从一个下拉列表开始以选择@department。
之后,我希望 Ransack 在@department 内搜索。
我需要在 Ransack 搜索参数中包含一个附加参数 department=2。 (如果我将它插入浏览器 URL 就可以了)。
我输入 department=2 后的浏览器 URL
http://localhost:5000/departments/costfuture?department=2&utf8=%E2%9C%93&q%5Bid_eq%5D=&q%5Bproject_year_eq%5D=&q%5Boriginal_year_eq%5D=&q%5Bclient_id_eq%5D=43&q%5Blocation_name_cont%5D=&q%5Bproject_name_cont%5D=&q%5Bcoststatus_id_in%5D%5B%5D=&q%5Bcoststatus_id_not_in%5D%5B%5D=&q%5Brebudget_true%5D=0&q%5Bnew_true%5D=0&q%5Bconstruction_true%5D=0&q%5Bmaintenance_true%5D=0&commit=Search
这是控制器:
def costfuture
@departments = current_user.contact.departments
if params[:department]
@department = Department.find(params[:department])
@search = @department.costprojects.future.search(params[:q])
@costprojects = @search.result.order(:department_priority)
end
respond_to do |format|
format.html # index.html.erb
format.json { render json: @departments }
end
end
我在视图中试过这个:
<%= search_form_for @search, url: departments_costfuture_path(:department => @department.id) do |f| %>
但是,生成的 URL 缺少 department=2。
【问题讨论】:
标签: ruby-on-rails ransack