Forum: Ruby on Rails Combining acts_as_taggable, will_paginate and scope_out

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Commander J. (Guest)
on 2009-04-26 18:53
(Received via mailing list)
I want to display published posts that are tagged using will_paginate.
Options include:

1. Add :conditions => { :published => true } to the find options. Does
not
work because will_paginate will then return too many records.
2. Use scope_out in class Post like this:

scope_out :published, :conditions => { :published => true }

Controller:

  def tagged_with
    @tag = params[:id]

    # Thanks go out to http://blog.wolfman.com/posts/33
    options = Post.find_options_for_find_tagged_with(@tag).merge(:page
=>
params[:page], :per_page => property(:items_per_page))
    #@posts = Post.paginate(options)
    @posts = Post.paginate_published(options)

    redirect_to :action => :tag_not_found if @Posts.empty?

    # Create a new comment in memory
    @comment = Comment.new( :Post => @Post)
  end

But this yields the error:

test_show_nonpublished_posts(FrontendControllerTest):
ActiveRecord::RecordNotFound: Couldn't find Post without an ID
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1572:in
`find_from_ids'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:616:in
`find'
(eval):2:in `find_published'
(eval):4:in `with_published'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2148:in
`with_scope'
(eval):3:in `with_published'
(eval):2:in `find_published'

Any ideas why?
Commander J. (Guest)
on 2009-04-26 19:04
(Received via mailing list)
Found! :D

Model:

  # XXL name to prevent override meta-methods such as paginate_published
  def self.paginate_all_published_posts(options)
    self.with_published do
      return self.paginate(options)
    end
  end

Controller:

@posts = Post.paginate_all_published_posts(options)

On Sun, Apr 26, 2009 at 4:52 PM, Commander J. <
This topic is locked and can not be replied to.