paginate works fine for index, but after search, only first page is
showed,
when I click “next” or “2”, the error appears.
ActiveRecord::RecordNotFound (Couldn’t find Server with ID=search):
app/controllers/servers_controller.rb:26:in `show’
It seems like paginate doesn’t know, params[:keyword],
I haven’t done anything for “def show” in servers_controller.rb.
def show @server = Server.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @server }
end
paginate works fine for index, but after search, only first page is
showed,
when I click “next” or “2”, the error appears.
ActiveRecord::RecordNotFound (Couldn’t find Server with ID=search):
app/controllers/servers_controller.rb:26:in `show’
[snip]
Check your routing and URLs. I suspect they don’t match for search.
paginate works fine for index, but after search, only first page is
showed,
when I click “next” or “2”, the error appears.
ActiveRecord::RecordNotFound (Couldn’t find Server with ID=search):
app/controllers/servers_controller.rb:26:in `show’
[snip]
Check your routing and URLs. I suspect they don’t match for search.
HTH,
Jeffrey
I added it to routes.rb
map.search ‘/search’, :controller => ‘servers’, :action => ‘search’
But I receive different error at this time,
TypeError in ServersController#search
can’t convert nil into String
It seems like paginate doesn’t no what keyword has been used for search
on next page,
so I changed view from <%= will_paginate @servers %> to
<%= will_paginate @servers, :params => {:keyword =>params[:keyword]} %>
“:params => {:keyword =>params[:keyword]}” this part is hand the
parameter to the next page.
What I have done is created search.html.erb instead of using
index.html.erb,
the only difference between search and index is
“:params => {:keyword =>params[:keyword]}”
and added routes.rb, and modified “def search” in servers_controller.rb
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @servers }
end
instead of
render :action => ‘index’
It works fine now.
Thank you Jeffrey.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.