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

The Archive Base Latest Questions

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

I’m all for the skinnier controller, fatter model mindset. I wanted to know how

  • 0

I’m all for the skinnier controller, fatter model mindset.

I wanted to know how to go about:

  1. How you identify things that should be moved to your model (assuming you’re like me and you get lazy and need to refactor your controllers because you just shove code in there)

  2. How you write and structure the creation of new elements in your controller. See following example.

Example

I had a relatively messy controller for a polymophic “vote”. I’ve cleaned it up pretty well, but I wanted to know if I could improve this action a little better:

def up
 vote = Vote.new
 vote.vote = true
 vote.voter = current_user    
 vote.voteable = Recipe.find params[:id]
 vote.save
end

To me it’s just a little ugly, and I probably should just use create instead of new, but I’m wondering if I’m driving down a deadly path here by using a non-standard action (concerning REST).

I’m working on switching it to new right now. But I definitely wanted to get the point of view of the community about.

  • 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-13T12:53:24+00:00Added an answer on May 13, 2026 at 12:53 pm

    The key to this is Test-Driven Development. Once you make it a habit, the question of where to put code is answered for you 95% of the time. Here’s why.

    Unit testing (model testing in Rails) is the easiest place to test code. Model methods should be unit tested “black box” style – meaning you don’t care what’s inside the method, only that input X provides output Y. This will also cause you to write a greater number of smaller methods in your model, instead of very large methods. The easier it is to test, the better – and not just for testing’s sake. Simpler methods are easier to override by other code, which is a big advantage of Ruby.

    Controller (functional) tests, on the other hand, will find you caring more about what happens inside the action, since those methods aren’t cut and dry input/output scenarios. Database calls happen, session variables are set, etc. Shoulda is a great test suite that automates a lot of this for you.

    Finally, my advice is to look inside some of your favorite plugins to see how they’re doing things. And if you’re interested more in testing, I have an article about restful controller tests in Shoulda that might get you started.

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

Sidebar

Related Questions

No related questions found

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.