search for: items_per_page

Displaying 20 results from an estimated 33 matches for "items_per_page".

2006 Apr 13
7
Complex SQL in paginate command?
Hi all, Is there a way to create pagination with a complex SQL, more complex than the :conditions option will support? I have two databases, houses and images. Houses has_many images, and each Image belongs_to house. I''m creating a search engine for the house records and I''d like to be able to filter out all the houses without any associated images. So far I''m
2005 Dec 19
6
custom find methods and pagination
i''ve got several methods in my models i use to find based on certain criteria...i''ve done this so the controller code is less cluttered, plus the DRY factor. example: class Foo < ActiveRecord::Base def find_by_something(something) find :all, :joins => ..., :conditions => ... end def find_by_something_else(something_else) find :all, :joins => ...,
2007 Jun 20
1
Count_by_content ??
Is there a count_by_content alternative to the find_by_content action? This is because I''m wanting to do the following in my pagination method: def list # step 1: set the variables you''ll need page = (params[:page] ||= 1).to_i items_per_page = 20 offset = (page - 1) * items_per_page # step 2: instead of performing a find, just get a count item_count = Item.count_with_some_custom_method() # step 3: create a Paginator, the second argument has to be the number of ALL items on all pages @item_pages = Paginator.new(sel...
2005 Dec 29
0
strange output in http header
...g the Content-Type from being set properly - look at the 4th line. Does anybody have any idea what might cause this? I''m using rails 0.13 and this problem occurs on both windows and debian, and only really causes a problem in firefox. The code that generates this is as follows: def tree items_per_page = 5 if !params[:items_per_page].nil? items_per_page = params[:items_per_page].to_i end @conditions = "parent_id IS NULL" logger.info params[:id] unless params[:id].nil? logger.info "creating discussion" @conditions += " AND creation_disc_id = "+params[:id] @discussion...
2006 Oct 02
6
Strange Sorting Issues
...uff goign on. Here''s my search method: sort_fields = [] sort_fields << Ferret::Search::SortField.new("name", :reverse => :false) @results = Listing.find_by_contents @search_criteria, :limit => :all, :sort => sort_fields page = (params[:page] ||= 1).to_i items_per_page = 9 offset = (page - 1) * items_per_page @pages = Paginator.new(self, @results.length, items_per_page, page) @results = @results[offset..(offset + items_per_page - 1)] For some queries, the sorting is correct. Other times, it''s not. I''m not sure what''s causing this....
2006 Jun 07
1
Reverse engineering pagination and more
Hey all, I''m building a photo album site (for fun) and have a few questions. 1) This site will have a browse section, where you can view the photos by thumbnail. I want to let the user change how many thumbs they can see per page. I''ll have a couple links at the bottom of the page letting them do that. The problem is, if they are in the middle of browsing and decide to
2008 Apr 26
0
moving pagination code to model
Hi I have the controller code as below # step 1: set the variables you''ll need page = (params[:page] ||= 1).to_i items_per_page = 20 offset = (page - 1) * items_per_page # step 2: instead of performing the full find, just find the record count @search_sd_ticket_count_result = ServiceDeskTicket.find_where(:all,:select=>''count(*) as count1'' ) do |sd|...
2008 May 19
0
changed to will_paginate
...y is as below .This is with the help of find_where pluggin..A fantastic pluggin which we still want to use...I would like to know how can i modify the following code to work with will_paginate step 1: set the variables you''ll need page = (params[:page] ||= 1).to_i items_per_page = 20 offset = (page - 1) * items_per_page # step 2: instead of performing the full find, just find the record count @search_sd_ticket_count_result = ServiceDeskTicket.find_where(:all,:select=>''count(*) as count1'' ) do |sd|...
2006 Apr 24
5
Custom pagination
I am trying to paginate objects from a has_many/:through relationship using Paginator. current_user.things returns the objects that I''d like to paginate. For testing, I tried to make it 1 item per page. I initialise the paginator as follows: @thing_pages = Paginator.new(self, current_user.things.count, 1, @params[''page'']) I don''t know how to obtain
2008 Mar 06
1
pagination for an object array
...def as below def search_sd_ticket @search_sd_ui_hash=params[:sd_ticket] @sd_ticket_number=@search_sd_ui_hash[:number] @sd_ticket_name = @search_sd_ui_hash[:name] # step 1: set the variables you''ll need page = (params[:page] ||= 1).to_i items_per_page = 20 offset = (page - 1) * items_per_page # step 2: instead of performing the full find, just find the record count @search_sd_ticket_count_result = ServiceDeskTicket.find_where(:all,:select=>''count(*) as count1'' ) do |sd|...
2007 Nov 20
2
Plugin: create instance methods dynamically in ClassMethods?
Hi all I have the following plugin code: module IncenseCrud def self.included(base_class) base_class.extend(ClassMethods) end module ClassMethods def performs_incense_crud def index list return render(:action => ''list'') end end end end In init.rb I have the following: require File.dirname(__FILE__) +
2006 Jul 16
3
pagination over custom-sorted collections?
I have a little web app where we need to paginate collections of items. I''m trying to sort the collection and then pass it, sorted, to a Paginator, and still be able to paginate through the collection, across several pages, with the new sort order. The only thing I''m doing differently from the regular scaffolding approach is this: @order_pages = Paginator.new(self,
2006 Aug 04
4
DRY DRY DRY
...m is not DRY at all! Few days ago I found http://dereksivers.com/rails-shared-controller.html I quite like his generic controller, not Nub class though ! And I''ve adopted it for my project as: controllers/basic_crud_controller.rb ... class BasicCRUDController < ApplicationController ITEMS_PER_PAGE = 15 before_filter :initialize_crud_controller verify :method => :post, :only => [ :destroy, :create, :update ], :redirect_to => { :action => :list } def index list end def list @items = model_class.find :all, :limit => ITEMS_PER_PAGE,...
2006 Apr 06
6
pagination question
i''ve figured out how to use the next and previous links with the paginator class but now i''m trying to figure out how to display all the page numbers in between. looking through the rails api, i found paginator.each() but i''m not sure how to use it, or if that''s even what i am looking for. also, is there a way to limit the amount of pages like some sites
2006 Jul 01
1
Paginator offset =0 ...
...st, I Try to do a custom paginator, but the offset never increase ?? def showFriends @friends_pages = Paginator.new self, allFriends.size, 3, @params[''page''] limit= @friends_pages.items_per_page offset= @friends_pages.current.offset logger.info("limit=#{limit}, offset=#{offset}") <==== ALWAYS 0 since params[''page''] =2 for @friends_list=allFriends.slice(offset,offset+limit) end I thought that the paginator object compute...
2006 Jan 26
1
Help constructing a find_by_sql command
Hello all. I am trying to do the equivalent of: @componentlogs = Componentlog.find(:all, :conditions => [ "cl_compname like ?", @criteria ], :offset => offset, :limit => items_per_page, :order => "cl_spr DESC" ) in a find_by_sql statement. I cannot use the build in because the adaptor isn''t quite right (OCI8) When I use it I get the following error OCIError: ORA-00907: missing right parenthesis: select * from (select raw_sql_.*, rownum raw_rnum_ from (SE...
2006 Jan 25
4
Cannot :order when using :offset and :limit in find
...escribed on the wiki but I am running into the following problem. The following code will work fine and retrieved unsorted records in a hunky dory fashion: @componentlogs = Componentlog.find(:all, :conditions => [ "cl_compname like ?", @criteria ], :offset => offset, :limit => items_per_page ) However if I try and add an order... @componentlogs = Componentlog.find(:all, :conditions => [ "cl_compname like ?", @criteria ], :offset => offset, :limit => items_per_page, :order => "cl_spr DESC" ) It goes totally doolally. OCIError: ORA-00907: missing right...
2005 Dec 16
13
How to pass a collection to paginate?
There must be a better way to write this code: @project_pages, @projects= paginate :project, :per_page => 10, :conditions => ["account_id = ?", account] ?! If only I could pass the sub-collection account = ... @projects = account.project to paginate, instead of letting it extract it with a find :all + sql conditions Alain. -- Posted via
2006 Apr 16
11
Best way to sort categories w/ pager
Ahoy, I made this pager, " def list @item_pages = Paginator.new self, Item.count, 10, @params[''page''] @items = Item.find :all, :conditions => "category_id = #{params[:condition]}", :limit => @item_pages.items_per_page, :offset => @item_pages.current.offset @categories = Category.find_all end" And have this code to switch categories "<table> <tr> <td><%= link_to ''all'', :action => ''list'' %></td&gt...
2006 Aug 11
0
Paginating HABTM?
Is there an easy way to paginate HABTM? Something like (which doesn''t work): @pages, @directories = paginate :directories, :include=>:categories, :per_page=>ITEMS_PER_PAGE directories and categories have an HABTM association. Joe -- Posted via http://www.ruby-forum.com/.