Acts_as_snook - Creating an admin panel

Posted over 2 years ago by Philip Ingram

Well, I’m going to try something a little different with this post. I’ll just post some code and explain one or two things that are out of the ordinary, instead of going through a full blow by blow account of it all.

Creating an Admin Panel for Acts As Snook

I basically needed to manage my comments and the resulting spam that is associated with having a blog on the interwebs. I haven’t created one as of yet, so here it is.

The stone cold facts of what i did

Simply put, i used my existing Admin Namespace to include a Comments Controller which listed all of the spam, ham and moderate comments available to me, through acts_as_snook .

Now, acts_as_snook has these methods which can update a Comment record from one status to another. E.g., spam to ham. Sometimes acts_as_snook can’t decide whether it’s spam or ham, so it goes into a moderate status and this is when those methods really shine.

The code…

Fix your routes by adding:

  
map.namespace :admin do |admin|
    admin.resources :comments, :member => {:ham_it => :get, :spam_it => :get}
  end

Next create an Admin::CommentsController and add:


class Admin::CommentsController < ApplicationController
  before_filter :get_comment, :except => :index
  def index
    @spam = Comment.spam
    @ham = Comment.ham
    @moderate = Comment.moderate
  end

def destroy @comment.destroy respond_to do |format| format.html { redirect_to(admin_comments_url) } format.xml { head :ok } end end #change to ham def ham_it @comment.ham! respond_to do |format| format.html { redirect_to(admin_comments_url) } format.xml { head :ok } end end #change to spam def spam_it @comment.spam! respond_to do |format| format.html { redirect_to(admin_comments_url) } format.xml { head :ok } end end protected def get_comment @comment = Comment.find(params[:id]) end

end

Finally we need a view to use, so why not add something like this:


<h1>Ham Comments (the good ones)</h1>
<% for ham in @ham %>
	<div id="admin_box">
		<p><%= ham.id %> in <%= post_title(ham.post_id) %> : <%= link_to 'Destroy', [:admin, ham], :confirm => 'Are you sure?', :method => :delete %> | <%= link_to "Spam", spam_it_admin_comment_path(ham) %></p>
		<p><%= h ham.body %></p></div>
<% end %>
<h1>Moderate Comments (the iffy ones)</h1>
<% for mod in @moderate %>
	<div id="admin_box">
		<p><%= mod.id %> in post #<%= post_title(mod.post_id) %> : <%= link_to "Spam", spam_it_admin_comment_path(mod) %> | <%= link_to "Ham", ham_it_admin_comment_path(mod) %></p>
		<p><%= h mod.body %></p></div>
<% end %>
<h1>Spam Comments (the bad ones)</h1>
<% for spam in @spam %>
	<div id="admin_box">
		<p><%= spam.id %> in post #<%= post_title(spam.post_id) %> : <%= link_to 'Destroy', [:admin, spam], :confirm => 'Are you sure?', :method => :delete %> | <%= link_to "Ham", ham_it_admin_comment_path(spam) %></p>
		<p><%= h spam.body %></p></div>
<% end %>

Remember, your Comment model schema may vary, but it’s probably similar.

Conclusion

Enjoy. I didn’t bore you with much other content then what was needed. This approach of course can be used to create any kind of admin moderation in an admin namespace.

Comments

I’m trying to set up a surveillance system!?
I took 1 st mortgage loans when I was 20 and that aided me a lot. However, I need the term loan once more time.
 Som en måte å sikre der HIV-positive filippinere kunne være tilstrekkelig beskyttet, eller selv hun oppfordret sin Institutt å gjøre med Helse og deretter Insurance Commission til finne for hvorvidt forsikringsselskapene har fått vært konstituert nær henhold bestående av Republic Act 8504 og selv sin AIDS Prevention ikke å nevne Kontroll Law.

"For forskere, en skala gir noen rask kategorisering tilkoblede med en planetens relevans som biologi, hele deres samme måte der det stellar typer umiddelbart kan fortelle en astronom noe om ett bestemt størrelse , temperatur, samt, lysstyrke assosiert med a stjerne "

Det er umulig må ikke slik at du kan varsel tips om hvordan god din utrolige hund sammen med katten føler når du gnir under sine haken aka klø bak ørene. De komfort blant hengivenhet simpelthen av konstant berøring kombinert med kjærtegn fører til over alle lykke og samt med mindre du er glad du ikke kan mektige være sunn, kan du?

Yahoooooooo!!! I have submitted my project well, and archieved the greatest grades in the study group, notwithstanding, it would be impossible to archieve that without an assistance of this marvelous online writers job organization.
m8C3sN comment6
See it for the first time!!….
Good! Wish everybody wrote so:DD
Internet is written with the capital letter in a sentence, by the way. And hundredths are written not with a point but with a comma. This is according to the standard. And actually everything is very good..!!
As usual, the webmaster posted correctly..!!
Informative, but not convincing. Something is missing but what I can not understand. But I will say frankly: bright and benevolent thoughts!….
Interesting. We are waiting for new messages on the same topic!!….
I am getting married on the 15th of November. Congratulate me! Then will be here rarely!…
The text is promising, will place the site to my favorites..!
Thank you, a very interesting note!!….
Can be also this issue because the truth can be achieved only in a dispute :DD
Strange but true. Your resource is expensive. At least it could be sold for good money on its auction!….
Somewhere in the Internet I have already read almost the same selection of information, but anyway thanks!!….
Well, actually, a lot of what you write is not quite true !… well, okay, it does not matter:DD
Right from this article begin to read this blog. Plus a subscriber:DD
I am getting married on the 15th of November. Congratulate me! Then will be here rarely!….
It’s pleasant sitting at work to distract from it�to relax and read the information written here:D
Strange but true. Your resource is expensive. At least it could be sold for good money on its auction!….
Yeah, in my opinion, it is written on every fence!!…
As I have expected, the writer blurted out..!!
Somewhere in the Internet I have already read almost the same selection of information, but anyway thanks!!….
It`s really useful! Looking through the Internet you can mostly observe watered down information, something like bla bla bla, but not here to my deep surprise. It makes me happy..!!
Very amusing thoughts, well told, everything is in its place:DD
Thank you, a very interesting note!!….
It’s straight to the point! You could not tell in other words! :DD
I almost accidentally visited to this site, but stayed here for a long time. Stayed because everything was very interesting. Surely will share with all my friends!…
Hello! How do you feel about young composers?!….
Yeah, it is clear now !… Just can not figure out how often do you update your blog?!….
Good day! I do not see the conditions of using the information. May I copy the text from here on my site if you leave a link to this page?!….
As I have expected, the writer blurted out..!!
Honestly, not bad news!….
07128c07baf4da1c3e38f902fe89366b sex
I am getting married on the 15th of November. Congratulate me! Then will be here rarely!….
Thanks for the news! Just was thinking about it! By the way Happy New Year to all of you:DD
Thanks for all the answers:) In fact, learned a lot of new information. Dut I just didn`t figure out what is what till the end!….
I am getting married on the 15th of November. Congratulate me! Then will be here rarely!….