will-paginate

Rails has_many conditions

六眼飞鱼酱① 提交于 2019-12-11 04:30:26
问题 c = "(f.profile_id = #{self.id} OR f.friend_id = #{self.id})" c += AND + "(CASE WHEN f.profile_id=#{self.id} THEN f.friend_id ELSE f.profile_id END = p.id)" c += AND + "(CASE WHEN f.profile_id=#{self.id} THEN f.profile_rejected ELSE f.friend_rejected END = 1)" c += AND + "(p.banned = 0)" I need this to be used in a has_many relationship like this: has_many :removed_friends, :conditions => ??? how do i set there the self.id?, or how do i pass there the id? Then i want to use the will_paginate

using lambda in find in rails

≡放荡痞女 提交于 2019-12-10 22:26:05
问题 I have a method that does a paginated find call like.. 1 coll = paginate(:all, lambda {{:conditions => ['status = ? AND expires < ?', 'a', DateTime.now]}}, :select => Constants::POST_FIELDS, :order => 'posts.ratings DESC', :include => [{:poster => :poster_friends}, :category], :per_page => Constants::LISTINGS_PER_PAGE, :page => page) When this call runs it simply ignores the conditions in the generated query. 2 If I try it in a named_scope I get an error like.. named_scope :featured_all,

Is it possible to use will_paginate with GROUP BY?

℡╲_俬逩灬. 提交于 2019-12-10 14:18:43
问题 I have a huge database and I want to reduce the query response time by using will_paginate. I am trying to group my entries by a column and then use the will_paginate to put results into different pages. I try to do this @list= Persons.find_by_sql(select).group_by {|t| t.gender} @detail= @list.paginate(:page => params[:page], :per_page => 30) but it gives me this error: (undefined method paginate for<Hash:0x3de9930>): Anyone know how to solve this problem? [Additional information] Someone on

will_paginate -error-undefined method `total_pages'

笑着哭i 提交于 2019-12-10 13:27:07
问题 I am using will_paginate "2.3.15" for my rails app in my units_controller.rb def index @units = Unit.paginate(:all ,:page => params[:page], :order => 'created_at DESC') end in my views(index) <%= will_paginate(@units)%> but it gives error undefined method `total_pages' for #<ActiveRecord::Relation:0xb523dc> my rails version 3.0.0 and ruby version 1.8.7 plz help 回答1: Why do you add the :all ? From the will_paginate wiki you should probably use : @units = Unit.paginate(:page => params[:page],

Testing views with will_paginate Gem using Capybara/Rspec

别来无恙 提交于 2019-12-10 10:47:50
问题 Doing Michael Hartl's Rails Tutorial, on chapter 10, section 5, exercise 2. I am - very simply - trying to write tests to ensure that a pagination div appears on a couple pages using the will_paginate gem (this seems to be Hartl's preferred method of testing whether pagination works), but when I add the following code.. subject { page } . . . it { should have_selector('div.pagination') } ..it returns.. 1) UserPages profile page Failure/Error: it { should have_selector('div.pagination') }

Undefined method `paginate'

淺唱寂寞╮ 提交于 2019-12-10 03:28:56
问题 I'm trying to use the will_paginate gem but something's wrong. I'm stuck with an undefined method `paginate' error. I read many issues and try a lot of things. Here's what I've got : This is my LocationsController.rb: def index @locations = Location.all respond_to do |format| @locations = @locations.paginate(:page => params[:page], :per_page => 10) format.html #index.html.erb format.json { render json: @locations } end end And this is my will_paginate's line in my index.html.erb : <%= will

How to customize the will paginate links with images

有些话、适合烂在心里 提交于 2019-12-08 13:46:54
问题 I want to customize the will paginate links in to dotted images instead of numbers 1,2,3. I tried to customize the css of pagination class but it wasn't worked. Pasted below the links format. (Existing) Previous 1 2 3 Next (Need to implement) . . . . . . . 回答1: I know this question is old, but perhaps you still want an answer. This is probably a good starting point. Create a helper such as app/helpers/will_paginate_helper.rb with the following content: module WillPaginateHelper class

will paginate with multiple tables

浪子不回头ぞ 提交于 2019-12-08 09:12:40
问题 I have following tables : users accounts ( user has_one account ) pictures ( user has_many pictures ) I want to display a User along with its related account and pictures. This is a typical N+1 queries problem and I solved it using eager loading. User.includes(:account, :pictures).all I am trying to use will_paginate gem. How do I include this eager loading mechanism into will_paginate ? I found a similar question here: Using will_paginate with multiple models (Rails). But the links in the

will_paginate helper undefined in sinatra with mongoid

China☆狼群 提交于 2019-12-08 08:57:47
问题 I am using sinatra 1.4.3 and mongoid 3.1.4. I tried adding will_paginate gem from master branch for mongoid support so I added this to my gemfile: gem 'will_paginate', :git => 'git://github.com/mislav/will_paginate.git', :branch => 'master' In environment.rb I added: require 'will_paginate' require 'will_paginate/mongoid' And pagination method started working. I have still problem with will_paginate helper. In my views I get errors like: NoMethodError: undefined method `will_paginate' for #

How to use pagination in rails 3.2.3?

守給你的承諾、 提交于 2019-12-08 05:48:56
问题 I'm new in RoR, and I want to include pagination in my application. Which is the best way to perform this task? Please suggest me. Is it possible to use will_paginate gem in rails 3.2.3 ? If yes, in which method I should include: Post.where(:published => true).paginate(:page => params[:page]).order('id DESC') Post.page(params[:page]).order('created_at DESC') 回答1: Yes, it is possible to use will_paginate gem in rails 3.2.3 applications. And the code will depends on what each action will