How to use acts-as-commentable-with-threading in Rails

人走茶凉 提交于 2019-12-24 22:17:40

问题


I am developing my first rails site (yup, i am a rails idiot). I'm writing a blog, and i got to the comments part. I installed acts-as-commentable-with-threading ( GitHub ), i made and ran the migration like the install instructions said. I have added acts_as_commentable to my Posts model and i have a Comments controller When i add

@comment = Comment.build_from(params[:id],1, params[:body] )

I get the error. undefined method `build_from' for #

Clearly i am doing something terribly wrong, and i don't really get the example. What should i be feeding to build_from? Can somebody explain this plugin step by step? :)

Or is there an easier way to get simple threaded comments?


回答1:


Did you by chance define your own comment model? If so that is going to completely override the model from the plugin that defines build_from in the first place. I ended up getting around this by creating a module with the extra stuff I wanted then creating an initializer to include it, which works perfectly.

As an aside, the first parameter to build_from needs to be the actual commentable object the comment is to be connected to, not just an id.

I'm currently using this plugin in production and can assure you it works :)




回答2:


Besides the reason of not restarting server (btw you shouldn't use nginx + passenger for development, simple mongrel or thin will do the job better in this case) I can think of two more:

  1. You didn't install plugin (or something wrong happened during installing). However this is unlikely as you could run migration ok right?
  2. You have comment model in app/models and rails doesn't load it from plugin. In this case you might want to try requiring file with plain old require.


来源:https://stackoverflow.com/questions/2917444/how-to-use-acts-as-commentable-with-threading-in-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!