lml / commontator

A Rails engine for comments
MIT License
353 stars 99 forks source link

Question: adding filter #32

Closed sepalaur closed 10 years ago

sepalaur commented 10 years ago

I added a "label" field to the commontator comments. Now I want to filter the comments displayed by using a form to select the label. Could you please give me some directions on the best way to do that?

Thanks a lot

sepalaur commented 10 years ago

I just filtered the comments variable at: https://github.com/lml/commontator/blob/master/app/views/commontator/threads/_show.html.erb#L60 With the get variable and it worked, thanks anyway!

Dantemss commented 10 years ago

You mean like tagging comments and clicking a tag to display only the comments with that tag?

That would probably require adding support for a tagging gem. I can try to do this, but probably not until the weekend.

Dantemss commented 10 years ago

Hm if you found an easy way to do it, I probably misunderstood what the problem was. Never mind.

sepalaur commented 10 years ago

It's what you said but in a very simple way: I added a column "label" to the commentator comments, and created a form with a "label" field, then I filtered the comments using something like:

<% filtered_comments = comments.where(:label=> params[:label]) %>

That's fine for me now!

sepalaur commented 10 years ago

Where is the code that updates inmediately the view when we edit a comment? (to do the same with my "label")

Dantemss commented 10 years ago

If you can put your label in app/views/commontator/comments/_body.html.erb, it should be automatic.

Otherwise, modify app/views/commontator/comments/update.js.erb to also reload the partial you are using.

sepalaur commented 10 years ago

I updated

app/views/commontator/comments/update.js.erb

and it worked, thanks!