Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6170343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:01:13+00:00 2026-05-23T23:01:13+00:00

I have made an application recently which has articles, etc, with a commenting/moderation system

  • 0

I have made an application recently which has articles, etc, with a commenting/moderation system on top. There are one of three things that happen when a user leaves a comment.

The first is if they are a registered user and logged in via Devise, their comment is flagged with a status of ‘2’ and gets published right away. If they are an anonymous user with a previously approved comment with a matching email address, comment gets status of ‘1’ and gets put into a moderation queue for approval. And if the user is completely brand new and their email isn’t in the system, that comment gets a status of ‘0’ and an email is sent to their inbox to click on a link to approve their email. After any of this, an appropriate notice/flash message is displayed.

I have all this working fine, but did nearly all the logic and variable definition in the controller, making the create action very fat. In the interest of learning best practices and the convention of ‘fat model, skinny controller,’ I am trying to move what logic I can into the Comment model, particularly the portion that figures out if they’re logged in or what. So hypothetically, something like this in the model…

attr_accessor :message
before_create :poster_type

def poster_type
  if current_user
    self.status = 2
    self.message = 'Your comment has been posted.'
  elsif Comment.find_by_mail(self.mail, :conditions => { :status => [1,2]}).present?
    self.status = 1
    self.message = 'Your comment has been sent for moderation.'
  else
    self.status = 0
    self.message = 'This is a new email, please confirm...'
  end
end

Problem is, you can’t use Devise’s current_user method (or others like user_signed_in?, etc) in the model, apparently. Every answer I have researched on this says unhelpfully that it isn’t the business of the model to access current_user values, etc.

However, I don’t exactly need to give the model a user’s information (as I’ve seen all other threads trying to do), all I need the method in the model to figure out is simply whether they’re logged in or not.

In addition, if you can’t use current_user (or other user detecting methods) in the model, then you would have no other choice than to define all the logic in the controller, and isn’t that bad practice as well? So if it’s possible, how can I do this logic in the model? Or should I simply just leave the controller fat?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:01:14+00:00Added an answer on May 23, 2026 at 11:01 pm

    You cannot access the devise user or session from any model due to separation of layers. What you can do is send the the object to the model.

    I’ve done something like your solution before and It was just a headache.

    So in your create action.

    def create
        if current_user
            @user.current_user(true)
        end
    end
    

    Then just send true/false to a method on the user:

    def current_user(current_user)
        current_user
    end
    

    Then you can have a before_create that checks if that is true.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web application which displays pdf's in an IFrame. I recently made
I have made some changes to a Classic ASP application which breaks foreign letters
I have made a custom UserControl i Vb.net (windows application). How can I add
I have made a SVG image, or more like mini application, for viewing graphs
I have an application that is made up of the following: A central database
I have an application where it was requested that a friendly url be made
I have to use a class/assembly made in C# .NET from native C++ application.
I have made some code which exports some details of a journal article to
I have made a new windows service which works fine using barebone code (just
I have made an application that can render and save a given element. With

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.