Custom pagination

In ci_controller i wrote

def search_ci
page = (params[:page] ||= 1).to_i
software_cis_per_page = 3
offset = (page - 1) * software_cis_per_page
@software_cis = SoftwareCi.find_by_sql([“select * from software_cis
where name like ? and status like ? and citype like ? and ci_class like
?”, “%” + params[:ci][:name] + “%”, “%” + params[:ci][:status] + “%”,
“%” + params[:ci][:citype] + “%”, “%” + params[:ci][:ci_class] + “%” ])
@software_ci_pages = Paginator.new(self, @software_cis.length,
software_cis_per_page, page)
@software_cis = @software_cis[offset…(offset + software_cis_per_page -
1)]
end

and in the view search_ci.rhtml,

<%= link_to(‘previous page’, {:params => params.merge(‘page’ =>
@software_ci_pages.current.previous)}) if
@software_ci_pages.current.previous %>
<%= ’ | ’ if @software_ci_pages.current.previous and
@software_ci_pages.current.next %>
<%= link_to(‘next page’, {:params => params.merge(‘page’ =>
@software_ci_pages.current.next)}) if @software_ci_pages.current.next %>

The first page is displayed. But when we click on the ‘next page’ an
error occurs… “can’t convert nil into String”

I printed the value in ‘page’ variable. It is 1 always.

any idea on how to fix this error.

On 18 Dec 2007, at 09:15, Suneeta Km wrote:

The first page is displayed. But when we click on the ‘next page’ an
error occurs… “can’t convert nil into String”

I printed the value in ‘page’ variable. It is 1 always.

I rather suspect that you want link_to(‘next page’,
params.merge(‘page’ => @software_ci_pages.current.next))
Looking at what rails thinks the params hash is should guide you on
your way

Fred

Frederick C. wrote:

On 18 Dec 2007, at 09:15, Suneeta Km wrote:

The first page is displayed. But when we click on the ‘next page’ an
error occurs… “can’t convert nil into String”

I printed the value in ‘page’ variable. It is 1 always.

I rather suspect that you want link_to(‘next page’,
params.merge(‘page’ => @software_ci_pages.current.next))
Looking at what rails thinks the params hash is should guide you on
your way

Fred

@software_cis has only the first 3 rows which is to be displayed in the
first page. But i’m not able to display the remaining rows in the next
page. Please suggest a solution to this.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs