Draiken / opinio

A rails 3 comments engine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

undefined method `default_per_page'

osfho opened this issue · comments

When using
<%= comments_for @blogpost %> or <%= render_comments @post %>, an error is raised:

undefined method `default_per_page' for #Class:0x10337a010

That is very weird.
That's a Kaminari method that should be added to all activerecord objects. I'm gonna check if they changed something.

could you please paste me your Gemfile.lock?

Thanks !

GEM
remote: http://rubygems.org/
specs:
actionmailer (3.1.0)
actionpack (= 3.1.0)
mail (> 2.3.0)
actionpack (3.1.0)
activemodel (= 3.1.0)
activesupport (= 3.1.0)
builder (
> 3.0.0)
erubis (> 2.7.0)
i18n (
> 0.6)
rack (> 1.3.2)
rack-cache (
> 1.0.3)
rack-mount (> 0.8.2)
rack-test (
> 0.6.1)
sprockets (> 2.0.0)
activemodel (3.1.0)
activesupport (= 3.1.0)
bcrypt-ruby (
> 3.0.0)
builder (> 3.0.0)
i18n (
> 0.6)
activerecord (3.1.0)
activemodel (= 3.1.0)
activesupport (= 3.1.0)
arel (> 2.2.1)
tzinfo (
> 0.3.29)
activeresource (3.1.0)
activemodel (= 3.1.0)
activesupport (= 3.1.0)
activesupport (3.1.0)
multi_json (> 1.0)
addressable (2.2.6)
arel (2.2.1)
bcrypt-ruby (3.0.1)
builder (3.0.0)
cocaine (0.2.1)
coffee-rails (3.1.1)
coffee-script (>= 2.2.0)
railties (
> 3.1.0)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.2.0)
daemons (1.1.6)
erubis (2.7.0)
eventmachine (0.12.10)
execjs (1.3.0)
multi_json (> 1.0)
faraday (0.7.6)
addressable (
> 2.2)
multipart-post (> 1.1)
rack (
> 1.1)
hike (1.2.1)
i18n (0.6.0)
jquery-rails (1.0.19)
railties (> 3.0)
thor (
> 0.14)
json (1.6.5)
kaminari (0.13.0)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
railties (>= 3.0.0)
mail (2.3.0)
i18n (>= 0.4.0)
mime-types (> 1.16)
treetop (
> 1.4.8)
mime-types (1.17.2)
multi_json (1.0.4)
multipart-post (1.1.4)
oauth (0.4.5)
oauth2 (0.5.2)
faraday (> 0.7)
multi_json (
> 1.0)
opinio (0.3.3)
jquery-rails
kaminari
rails (> 3.0)
paperclip (2.5.0)
activerecord (>= 2.3.0)
activesupport (>= 2.3.2)
cocaine (>= 0.0.2)
mime-types
polyglot (0.3.3)
rack (1.3.6)
rack-cache (1.0.3)
rack (>= 0.4)
rack-mount (0.8.3)
rack (>= 1.0.0)
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
rack (>= 1.0)
rails (3.1.0)
actionmailer (= 3.1.0)
actionpack (= 3.1.0)
activerecord (= 3.1.0)
activeresource (= 3.1.0)
activesupport (= 3.1.0)
bundler (
> 1.0)
railties (= 3.1.0)
railties (3.1.0)
actionpack (= 3.1.0)
activesupport (= 3.1.0)
rack-ssl (> 1.3.2)
rake (>= 0.8.7)
rdoc (
> 3.4)
thor (> 0.14.6)
rake (0.9.2.2)
rdoc (3.12)
json (
> 1.4)
sass (3.1.12)
sass-rails (3.1.5)
actionpack (> 3.1.0)
railties (
> 3.1.0)
sass (> 3.1.10)
tilt (
> 1.3.2)
sorcery (0.7.6)
bcrypt-ruby (> 3.0.0)
oauth (
> 0.4.4)
oauth (> 0.4.4)
oauth2 (
> 0.5.1)
oauth2 (> 0.5.1)
sprockets (2.0.3)
hike (
> 1.2)
rack (> 1.0)
tilt (
> 1.1, != 1.3.0)
sqlite3 (1.3.5)
thin (1.3.1)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.31)
uglifier (1.2.2)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)

PLATFORMS
ruby

DEPENDENCIES
coffee-rails (> 3.1.0)
jquery-rails
json
opinio
paperclip
rails (= 3.1.0)
sass-rails (
> 3.1.0)
sorcery
sqlite3
thin
uglifier

Okay, by my tests the only way I could make this happend is if the opinio model is not an active_record model.

Did you change your opinio initializer model_name?
Does your comment class (or whatever it's called) extends ActiveRecord?

Nope, didn't change the initializer model_name and my comment class (Blogpost) does indeed extend ActiveRecord. :(

so, the comment class is Comment and the Blogpost is with opinio_subjectum in it?

Correct!

anyhow, a simple "monkey patch" is to pass to the helper (render_comments or comments_for) the :limit option with a number of comments to show.

Normally it tries to get the default_per_page from the Comment model, if the :limit option is not passed.

I am currently at work so I will take a deeper look at this at my lunch time.

This should work:

<%= comments_for @blogpost, :limit => 10 %>

Hey, I appreciate you taking the time to help me out at all! I'll work with the monkey patch in the meantime.

Thanks so much!

Could you tell me what ruby version are you using?

Okay I confirmed this is a Kaminari issue. If you don't want the monkey patch, just put gem 'kaminari', '0.12.4' on your Gemfile and run bundle update kaminari.

It should work fine.

I will submit this bug to kaminari so you can remove that version restriction from your Gemfile

oh well, tested kaminari alone and there is no bug... I'm investigating what changed in kaminari that is conflicting with opinio...

ruby 1.8.7 (2010-06-23 patchlevel 299) [i686-darwin10]

Should I be using 1.9?

Shouldn't be an issue. It's your app :)

I reproduced the problem, then it just went away without me changing anything :/
I'll keep looking for some way to fix this...

Any news on this issue?
I haven't been able to reproduce it since last I tried.

I have this issue. I threw together an ultra-simple rails app that demonstrates the issues: https://github.com/kkuchta/OTest

The only commands of consequence on that app were "rails g scaffold Post title:string body:string" and the instructions from the Opinio readme. Going to http://localhost:3000/posts, creating a new post, and then viewing http://localhost:3000/posts/1 give the undefined method 'default_per_page' error.

I think I'm gonna force opinio to take the 0.12.4 version of kaminari instead of the 0.13 while we don't fix this damn issue.
I have no clue of what's causing this. I tried running the same command on the console and no error is given. Must be some kind of load issue, but kaminari should be already loaded when the helper is called, therefore adding the default_per_page method.
I don't want to make an extra option on Opinio to paginate this stuff, it should use kaminari since it's already there and people use it. I will take another look at this monday morning.

Thanks for the sample app @kkuchta

I cannot believe how stupid this issue is...
kaminari is marked as a gem dependency on the gemspec and it's installed but it's never required by opinio.

I will add the gem on the opinio generator.

New version up

Awesome- works fine in my real app. Thanks for the quick update!