我试图创建一个简单的表单,允许我对现有的'结果进行新的搜索。页面使用简单的形式。
从另一个(登陆)页面执行搜索时,完全相同的代码可以正常工作。但是,当我尝试将其插入到结果页面中时,我正在
undefined method 'vtype' for #
<Venue::ActiveRecord_Relation:0x007fd6860eb730>
vtype
既是表格列,也是传递给搜索的参数名称。
simple_form如下所示:
<%= simple_form_for :results, html: { class: "form-inline justify-content-center" } do |f| %>
<%= f.error_notification %>
<%= f.select :vtype, options_for_select([['Happy Hours Anywhere','Anywhere'],['After Work Drinks','After Work Drinks'],['Somewhere to Relax with Friends', 'Relaxing with Friends'], ['A Club Night','Club Night'], ['Somewhere for Date Night','Date Night'], ['A Place to Watch Sports', 'Watching Sports']]),{} ,:class => "form-control select-box font-lightweight" %>
starting
<%= f.select :date, options_for_select(dates_for_search_select.each_with_index.map{|d, i| [d[1],d[0]]}), {}, :class => "form-control select-box font-lightweight" %>
at
<%= f.select :time, options_for_select(times_for_search_select.each_with_index.map{|d, i| [d[1],d[0]]}), {}, :class => "form-control select-box font-lightweight" %>
</h4>
<%= f.button :submit, 'Discover', :class => 'btn btn-block btn-danger btn-embossed top-margin ' %>
<%end%>
我的控制器看起来像这样:
def results
if params.has_key?(:results)
#@results = Venue.joins(:offers).where("offers.offertype = '2-4-1'")
@finddate = (params[:results][:date]).to_date
@findtime = (params[:results][:time]).to_time
@resultsdate = DateTime.new(@finddate.year,@finddate.month,@finddate.day,@findtime.hour)
@results = Venue.joins(:offers).where(["venues.vtype = ? and offers.start >= ?", params[:results][:vtype], @resultsdate])
else
@results = Venue.joins(:offers).where(["offers.start = ?", Date.today])
end
end
这个表单在&#39;结果&#39;上运行有什么问题?网页?