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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:33:08+00:00 2026-05-14T18:33:08+00:00

More and more I’m putting all of my code in models and helpers concerning

  • 0

More and more I’m putting all of my code in models and helpers concerning MVC.

However, sometimes I’m not sure where to organize code. Should it go into the model or should it go into a helper. What are the benefits of each. Is one faster or are they the same. I’ve heard something about all models getting cached so it seems then like that would be a better place to put most of my code.

For example here is a scenario that works in a model or in helper:

 def status
  if self.purchased
   "Purchased"
  elsif self.confirmed
   "Confirmed"
  elsif self.reserved
   "Reserved"
  else
   "Pending"
  end

end

I don’t need to save this status as in the database because there are boolean fields for purchased, and confirmed, and reserved. So why put this in a model or why put it into a helper?

So I’m not sure of the best practice or benefits gained on putting code into a model or into helper if it can be in both.

  • 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-14T18:33:09+00:00Added an answer on May 14, 2026 at 6:33 pm

    Your specific example is including a business rule in the sense that if the instance of the model is both purchased and confirmed then the proper status is “purchased” not “confirmed”

    So in your example, I’d definitely put the method in the model since it is coding one of your applications business rules.

    A different example:

    def status_string
      case status
        when 0: "Purchased"
        when 1: "Confirmed"
        else
          "Pending"
       end
    end
    

    In this case, the status_string method could be reasonably defined either in a View Helper or Model–it has nothing to do with any business rules, it is changing the representation of the value. I’d put it in the model since I tend to only put html-related sw into the View Helpers. But depending on your internationalization scheme, a similar method might be better placed in the View Helper.

    A good example of a View Helper is an application-wide method to transform date time values into the standard representation for your app. Eg

    # application_helper.rb
    def date_long_s(d)
      d.strftime("%A, %b *%d, %Y *%I:%M %p")
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

More specifically, I'm not sure what the % and \ symbols coming right after
//more code omitted that is not relevant, the IF template is not completely shown
More than one time I have encountered the following problem when building code with
More WCF woes... :) All my workflows implement the same 3 methods. After a
(More package/component install fun for me -- thanks everyone for all your help to
More sanity checking than an actual question, so this dll is not signed? Does
More specifically, I'm looking for how to count the number of lines in all
More specifically the STM32F107 . I could barely find any code on ST's website,
More of an architecture / long-term view question. I'm in the process of putting
More specifically, I put a breakpoint in my code after NSString *signStr = [NSString

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.