Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8595603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:28:30+00:00 2026-06-12T00:28:30+00:00

ok here is my problem. i make a simple search with title. it work

  • 0

ok here is my problem. i make a simple search with title.
it work but with paginate dont!

contollers>store_controller

class StoreController < ApplicationController
  def index

  @buildings = Building.search(params[:search])

  @buildings = Building.paginate :page=>params[:page], :order =>'created_at DESC', :per_page=>10

 end

end

model>building

  def self.search(search)
  if search

    find(:all, :conditions => ['title LIKE ?', "%#{search}%"])
   else
    find(:all)
  end
end

views>store

 <% if notice%>
<p id="notice"> <%= notice%></p>
<%end%>

<h1>All Priorities</h1>

 <%= form_tag  store_path, :method => 'get'  do %>
<p>
  <%=text_field_tag :search , params[:search]%>
  <%= submit_tag "Search", :name=> nil%>
  </p>
  <%end%>


<% @buildings.each do |building| %>
<div class="entry">
    <div class="img">
    <%= image_tag (building.photo.url)%></div>
    <div class=" disc">
    <h3>Name of the Bulding:  <%= building.title %></h3>
     <h4>Status: <%= building.status %></h4>
    Info: <%=sanitize(building.description)%>
    <div class="price_line">
        <span class="price">Price: <%= sprintf("€ %0.02f",building.price)%></span><br/>
        <div class="button">
        <%= button_to("I want to see it", {:controller => "seeits", :action => "new", :building_id => building.id})%></div>


    </div>

    <div class="pages">
<%= will_paginate @buildings %></p>
</div>

    </div>

</div>


<%end%>

controllers>building

class BuildingsController < ApplicationController
  # GET /buildings
  # GET /buildings.json
  def index 

    @buildings = Building.all

      respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @buildings }
    end

  end

if i have it this way the search does not work and shows me all the buildings. but if i remove from views>store :

<div class="pages">
    <%= will_paginate @buildings %></p>
    </div>

and from contollers>store_controller :
@buildings = Building.paginate :page=>params[:page], :order =>'created_at DESC', :per_page=>10

it work fine! but i want to paginate when the user is on first side and doesn’t do search

UPDATE 1

controllers>store

class StoreController < ApplicationController
   def index


    # load @buildings following authorizations, whatever...
    # for instance, if you use cancan and load_and_authorize_resource, you'll have
    # already a @buildings you'd want to use, otherwise load them
    @buildings = Building.all
    # or @buildings = current_user.buildings or whatever makes sense

    @buildings = @buildings.search(params[:search]) if params[:search].present?

    @buildings = @buildings.paginate(:page=>params[:page],
                                     :order =>'created_at DESC',
                                     :per_page=>10)
    # do things, render etc...
  end

end

models>building

class Building < ActiveRecord::Base
 scope :search, lambda { |text| where('buildings.title LIKE ?', "%#{text}%") }

end

the problem remains! error: undefined method `paginate’ for #

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:28:32+00:00Added an answer on June 12, 2026 at 12:28 am

    You want to paginat the results of the search, don’t paginate again the whole Building table!

    class StoreController < ApplicationController
      def index
    
        # load @buildings following authorizations, whatever...
        # for instance, if you use cancan and load_and_authorize_resource, you'll have
        # already a @buildings you'd want to use, otherwise load them
        # or @buildings = current_user.buildings or whatever makes sense
    
        @buildings ||= Building.scoped
    
        @buildings = @buildings.search(params[:search]) if params[:search].present?
    
        @buildings = @buildings.paginate(:page=>params[:page],
                                         :order =>'created_at DESC',
                                         :per_page=>10)
        # do things, render etc...
      end
    
    end
    

    and, that search classmethod is in fact a scope:

    class Building < ActiveRecord::Base
      scope :search, lambda { |text| where('buildings.title LIKE ?', "%#{text}%") }
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Got a problem which to me make no sense. So here goes: I have
Simple problem, though apparently not a simple solution. Example here: http://myhideout.eu/new/ Basically the site
I'm trying to make a simple search and return results in a paginated form.
I'm tryin to implement a simple random search algorithm in Java here's a piece
I'm trying to make a simple search form on my website and I'm using
I have a small problem, looked here & other forums, but could not find
Recently I create a mapping to toggle highlight search. That's simple but quite useful,
I got some problems here, I can't make my find_by_sql request to render an
The problem here is how to add an NSPopUpButton in Xcode 4's Interface Builder
Maddening problem here. When my page loads: <body onload=getClientDateTime();> It runs this function: document.getElementById('ClientDateTime').value=hello

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.