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 8819369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:20:28+00:00 2026-06-14T05:20:28+00:00

I have heard several views on MVC structure in a web application. Some people

  • 0

I have heard several views on MVC structure in a web application. Some people believe the model should be very small, and only contain ActiveRecord (or some other ORM) and small things like validates and belongs_to, so model’s are only a couple lines long.

I personally think the model can play a larger role in apps. For example, I need to notify a user frequently throughout my app. The notifications can trigger from multiple controllers. They all send a notification to a user based on his or her notification settings, which is an object accessible through the user model.

I would like to make something like:

class User < ActiveRecord::Base
  #validations, relationships, etc

  def notify(event)
    notif = Notification.new
    notif.type = event.type
    notif.to = self.id
    # etc

    if notif.save
      # send the notification based on the settings
    end
  end
end

This would make it possible from any controller to use @user.notify to deliver messages to a user. This makes things really clean, but I realize there is some logic in my model. Not to mention the model makes another model.

Another approach I wouldn’t mind is creating the notification and sending it through that object. So controllers could do Notification.new(:to => @user.id, ...) and then deliver the message via a Notification.send. This would also put some logic in the Notification object so it knows how to send itself. In fact, I might like this approach better than creating the notification object through the User model.

I don’t mind these small bits of logic in the Model to make things convenient when sending messages from multiple controllers. Is this the best way to go about it? I suppose a more purist method is to include a NotificationHelper module in each controller that sends notifications?

edit: I’ve been reading a bit about “domain logic” in models. It seems like this is encouraged, and I suppose the notify or send methods are considered domain logic. Can any developer experienced in MVC comment on this?

  • 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-06-14T05:20:30+00:00Added an answer on June 14, 2026 at 5:20 am

    For your second approach you can use ActiveRecord::Observer

     class NotificationObserver < ActiveRecord::Observer
       def after_create(notification)
           # some sending logic
       end
     end
    

    But don’t be shy extract small pieces of logic into their own classes, like

    lib/user_notify.rb

     class UserNotify
       def event_trigger(user,event)
           # some logic
       end
     end
    

    use naming concepts suitable for your system (maybe Notify.send_user_about_event, etc.)

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

Sidebar

Related Questions

I have an MVC application with a single model and several views (something like
I have heard that prepared statements with SQLite should improve performance. I wrote some
I have heard several people claiming that you can not scale the JVM heap
I have been working very hard on several very long views which are attached
Firefox 3 came with a new allocator: jemalloc . I have heard at several
I have heard a lot of people in the Magento community mention the benefits
I have heard that web-based chat clients tend to use networking frameworks such as
I have heard that DateTime.Now is very expensive call (from here ) Is GETDATE()
I have heard of types being referred to as boxed in some languages. In
I have several partial views with Javascript that I am trying to move to

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.