好的,我有一张表格
<form action="/search" method="post">
<input type="hidden" name="location_id" value="1" /><br />
<input class='small' data-datepicker='datepicker' name='start_date' type='text' value='03-09-2012'>
<input class='small' data-datepicker='datepicker' name='end_date' type='text' value='03-09-2012'>
</form>
我有路线
match "/search", :to => "locations#search"
并在我的控制器中
def search
@location = Location.find(params[:location_id])
start_date = DateTime.strptime(params[:start_date], "%m-%d-%Y")
end_date = DateTime.strptime(params[:end_date], "%m-%d-%Y")
@songs = @location.songs.paginate(:page => params[:page], :per_page => 30, :conditions => {:play_date => start_date..end_date})
render 'show'
end
当我点击第2页或下一页页面错误时,所有的作品都很完美,因为我没有在params中的location_id或日期....任何关于如何解决这个问题的想法...我正在使用will_paginate宝石
错误
Couldn't find Location without an ID
参数:
{"page"=>"2"}
答案 0 :(得分:1)
您需要将location_id参数添加到您的will_paginate视图助手中,如下所示:
<%= will_paginate @some_objects, :params=>{:location_id=>@location.id} %>
希望它有所帮助。