Note that there are some explanatory texts on larger screens.

plurals
  1. POsearch with ror
    primarykey
    data
    text
    <p>ok here is my problem. i make a simple search with title. it work but with paginate dont!</p> <pre><code>contollers&gt;store_controller class StoreController &lt; ApplicationController def index @buildings = Building.search(params[:search]) @buildings = Building.paginate :page=&gt;params[:page], :order =&gt;'created_at DESC', :per_page=&gt;10 end end </code></pre> <p>model>building</p> <pre><code> def self.search(search) if search find(:all, :conditions =&gt; ['title LIKE ?', "%#{search}%"]) else find(:all) end end </code></pre> <p>views>store</p> <pre><code> &lt;% if notice%&gt; &lt;p id="notice"&gt; &lt;%= notice%&gt;&lt;/p&gt; &lt;%end%&gt; &lt;h1&gt;All Priorities&lt;/h1&gt; &lt;%= form_tag store_path, :method =&gt; 'get' do %&gt; &lt;p&gt; &lt;%=text_field_tag :search , params[:search]%&gt; &lt;%= submit_tag "Search", :name=&gt; nil%&gt; &lt;/p&gt; &lt;%end%&gt; &lt;% @buildings.each do |building| %&gt; &lt;div class="entry"&gt; &lt;div class="img"&gt; &lt;%= image_tag (building.photo.url)%&gt;&lt;/div&gt; &lt;div class=" disc"&gt; &lt;h3&gt;Name of the Bulding: &lt;%= building.title %&gt;&lt;/h3&gt; &lt;h4&gt;Status: &lt;%= building.status %&gt;&lt;/h4&gt; Info: &lt;%=sanitize(building.description)%&gt; &lt;div class="price_line"&gt; &lt;span class="price"&gt;Price: &lt;%= sprintf("€ %0.02f",building.price)%&gt;&lt;/span&gt;&lt;br/&gt; &lt;div class="button"&gt; &lt;%= button_to("I want to see it", {:controller =&gt; "seeits", :action =&gt; "new", :building_id =&gt; building.id})%&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="pages"&gt; &lt;%= will_paginate @buildings %&gt;&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;%end%&gt; </code></pre> <p>controllers>building</p> <pre><code>class BuildingsController &lt; 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 </code></pre> <p>if i have it this way the search does not work and shows me all the buildings. but if i remove from views>store : </p> <pre><code>&lt;div class="pages"&gt; &lt;%= will_paginate @buildings %&gt;&lt;/p&gt; &lt;/div&gt; </code></pre> <p>and from contollers>store_controller : <code>@buildings = Building.paginate :page=&gt;params[:page], :order =&gt;'created_at DESC', :per_page=&gt;10</code></p> <p>it work fine! but i want to paginate when the user is on first side and doesn't do search </p> <p>UPDATE 1</p> <p>controllers>store</p> <pre><code>class StoreController &lt; 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=&gt;params[:page], :order =&gt;'created_at DESC', :per_page=&gt;10) # do things, render etc... end end </code></pre> <p>models>building</p> <pre><code>class Building &lt; ActiveRecord::Base scope :search, lambda { |text| where('buildings.title LIKE ?', "%#{text}%") } end </code></pre> <p>the problem remains! error: undefined method `paginate' for #</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload