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

  • Home
  • SEARCH
  • 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 48761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:19:50+00:00 2026-05-10T16:19:50+00:00

I want to log user’s actions in my Ruby on Rails application. So far,

  • 0

I want to log user’s actions in my Ruby on Rails application.

So far, I have a model observer that inserts logs to the database after updates and creates. In order to store which user performed the action that was logged, I require access to the session but that is problematic.

Firstly, it breaks the MVC model. Secondly, techniques range from the hackish to the outlandish, perhaps maybe even tying the implementation to the Mongrel server.

What is the right approach to take?

  • 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. 2026-05-10T16:19:51+00:00Added an answer on May 10, 2026 at 4:19 pm

    I find this to be a very interesting question. I’m going to think out loud here a moment…

    Ultimately, what we are faced with is a decision to violate a design-pattern acceptable practice in order to achieve a specific set of functionality. So, we must ask ourselves

    1) What are the possible solutions that would not violate MVC pattern

    2) What are the possible solutions that would violate the MVC pattern

    3) Which option is best? I consider design patterns and standard practices very important, but at the same time if holding to them makes your code more complex, then the right solution may very well be to violate the practice. Some people might disagree with me on that.

    Lets consider #1 first.

    Off the top of my head, I would think of the following possible solutions

    A) If you are really interested in who is performing these actions, should this data be stored in the model any way? It would make this information available to your Observer. And it also means that any other front-end caller of your ActiveRecord class gets the same functionality.

    B) If you are not really interested in understanding who created a entry, but more interested in logging the web actions themselves, then you might consider ‘observing’ the controller actions. It’s been some time since I’ve poked around Rails source, so I’m not sure who their ActiveRecord::Observer ‘observes’ the model, but you might be able to adapt it to a controller observer. In this sense, you aren’t observing the model anymore, and it makes sense to make session and other controller type data information to that observer. C) The simplest solution, with the least ‘structure’, is to simply drop your logging code at the end of your action methods that you’re watching.

    Consider option #2 now, breaking MVC practices.

    A) As you propose, you could find the means to getting your model Observer to have access to the Session data. You’ve coupled your model to your business logic.

    B) Can’t think of any others here 🙂

    My personal inclination, without knowing anymore details about your project, is either 1A, if I want to attach people to records, or 1C if there are only a few places where I’m interested in doing this. If you are really wanting a robust logging solution for all your controllers and actions, you might consider 1B.

    Having your model observer find session data is a bit ‘stinky’, and would likely break if you tried to use your model in any other project/situation/context.

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

Sidebar

Ask A Question

Stats

  • Questions 68k
  • Answers 68k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer They look like lables for use as goto targets. See… May 11, 2026 at 12:23 pm
  • added an answer See XML Schema Part 0: Primer for a very concise… May 11, 2026 at 12:23 pm
  • added an answer You don't even need this code, but I think the… May 11, 2026 at 12:23 pm

Related Questions

I want to log user's actions in my Ruby on Rails application. So far,
I want to log onto Stack Overflow using OpenID, but I thought I'd set
I want to log to the console when I'm using un-minimized JavaScript files. Comments
I want to add some Ajax -niceness to my Django-coded website. In my Django
I want to run a web application on php and mysql, using the CakePHP

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.