Working in install acts_as_commentable, On create, error: "unknown attribute: book_id"

Hello, I’m working to install the acts_as_commentable plugin on my
Rails 3 app.

After adding “acts_as_commentable” to my book model, I then added a
comment form on my book show view:

<% form_for(@comment) do|f| %>
<%= f.hidden_field :book_id %>
<%= f.label :comment %>

<%= f.text_area :comment %>
<%= f.submit “Post Comment” %>
<% end %>

Then in the controller (comments_controller.rb),
def create
@comment = Comment.new(params[:comment])
Book.comments.create(:title => “First comment.”, :comment => “This
is the first comment.”)
end

Then when submitting a comment, it returns the error: “unknown
attribute: book_id”

From the log:
Processing by CommentsController#create as HTML
Parameters: {“comment”=>{“comment”=>“WOOOW”, “book_id”=>“32”},
“commit”=>“Post Comment”,
“authenticity_token”=>“5YbtEMpoQL1e9coAIJBOm0WD55vB2XRZMJa4MMAR1YI=”,
“utf8”=>“✓”}
Completed in 11ms

ActiveRecord::UnknownAttributeError (unknown attribute: book_id):
app/controllers/comments_controller.rb:3:in new' app/controllers/comments_controller.rb:3:increate’

Suggestions?

i made an example app for kelp kelp , it has threaded comments and
polymorphic associations, tested on rails 3, you can see it at

http://github.com/rbritom/Simple_polymorphic_nested_comments

watch the code and do it your self, i think is better than using that
gem,
since is really easy to achieve with out the gem.

I added lots of comments so that you can understand whats going and
added
some ajax, if you need more explanations just ask.

Thanks, that looks interesting and helpful… Couple comments:

What is lft rgt for in the database?

Also, proyects should be spelled projects…

Does nesting currently work is are you still working on implementing
it?

I’d still be interested in knowing y I’m hitting the bug above, any
ideas?

oh , awsome nested set gem arrenges item like a tree , to is like

                                         root
                                            |
                              ________|__________
                       left  |            item             | right
                  ______ |__           |      ______|______

you see item has a left and right sibling, the gem saves , the
parent_id
of item , in this case root and the item of the item to the left and to
the
right

On Tue, Sep 21, 2010 at 4:49 PM, radhames brito [email protected]
wrote:

Very interesting, new to me…

Does nesting currently work in your example app OR are you still
working on implementing
it? I’m trying to decide if nesting isn’t yet done, if I should wait
until it’s up and working?

everything works it only lacks the comments

im going to update in 5 minutes , i added ajax pagination

In 15 minutes im going to add ajax to the destroy action and a loading
gif

Nice can’t wait to try it out… Why not turn this into a Rails 3
Gem / plugin?

check it out i cant think of any more features to add. See if you can
think
of something =D

Very nice thanks, I’m trying it out now.

don’t really have the need for pagination but it’s helpful as a
learning tool/tutorial of sorts…

regarding a feature to add, I can actually think of one very common
feature, as seen on Facebook. If you have over 3 comments, to only
show the latest 2 comments, and then have a ajax link “View all X
comments” which when clicked loads/injects the remaining comments into
the comment list. That’s a pretty important one! A less important one,
is being able to LIKE a comment.

Sound interesting?

ill think about it, i have never done one before.

To get your code working in my app I needed to:
@comments = @article.comments.roots.order(“created_at
DESC”).paginate( :page => params[:page]||1,:per_page => 5)
REMOVE roots in books_controller.rb:
@comments = @article.comments.order(“created_at DESC”).paginate( :page
=> params[:page]||1,:per_page => 5)

And in comment.rb:
COMMENT OUT #acts_as_nested_set

Otherwise I get the error on the books show page: “uninitialized
constant Book::Comment”

Is there a GEM that needs to be installed? Or maybe this isn’t
supported for Rails 3?

It would also be create if

def create
@comment = @commentable.comments.build(params[:comment])

Passed along the current_user as I added user_id to the comments
table :slight_smile:

oohh very good ones , ill surely put them

the projet is done i rails three and the awesome nested set is in there
as a
plug in, is what does the nesting, if you dont use it the nesting wont
work,
can you give me more info on you book model? i want know why is not
working

well i left that out because it would make the example a little harder
to
follow what i will do is a second example that will integrate users,
then
one with users and captcha, i will add funcionality on topp of the
existing
one but as a new project so is easy to learn what’s news

On Sep 22, 3:48 am, radhames brito [email protected] wrote:

the projet is done i rails three and the awesome nested set is in there as a
plug in, is what does the nesting, if you dont use it the nesting wont work,
can you give me more info on you book model? i want know why is not working

Is the plug-in in the GEM file? I’m not seeing it. Could you point it
out so I can add it to my GEM file? If the plugin isn’t via the GEM
file, how do you get it added to the rails 3 app?

Thanks!

no , plugins go along with the rails app. gems get installed in the
computer
your are using and if you take your rails app somewhere else you have to
install all the gems in that other computer, plugins install in the
/vendor/plugin folder in the rails app and they go where ever you app
goes,
the result is almost the same but , gems are better if you have several
project using something common, for example , most rails app use
will_paginate so is better to install it as a gem on the pc, if you
install
will paginate as a plugin you would have a copy of will_paginate in each
app, and also your app would grow as you put plugins in them.

At then i installed awesome nested set as a plugin in the vendors/plugin
directory because i needed to hack it, is not a good idea to hack a gem
as
gems as i explained are shared by all the apps in that computer.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs