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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:51:43+00:00 2026-05-26T15:51:43+00:00

I’m wondering when you know that you need to create a controller in a

  • 0

I’m wondering when you know that you need to create a controller in a rails application.

For example, I’m going through the tutorial in Agile Web Development with Rails and the application creates several models, all with seperate views and contollers. However, we also then create a Store controller, but no model associated with it. Why do we need a controller with no model? Couldn’t the controllers for the models handle all required operations?

Is this common? If so, how do you determine when something warrants a controller?

Thanks!


These answers help, thank you.

My concern is that when I develop something on my own, I will begin to create useless controllers, or on the flip side, not create necessary controllers. But, I suppose I need to stop thinking of controllers and models as a 1-1 relationship, correct? If I’m understanding correctly, there could be many controllers accessing a model and many models being used in one controller?

  • 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-26T15:51:43+00:00Added an answer on May 26, 2026 at 3:51 pm

    UPDATE: I highly recommend reading How DHH Organizes His Rails Controllers
    which pretty much explains it much better than my original answer.


    I think the question would be more suitable if you’d put it another way:

    Why do we need model (AR in this case) for every controller?

    And the answer of course is, you don’t. When you are thinking about controllers it’s best not to think about data, but take a slight step back, and think about resources. If you search for REST in internet, you will find a lot of articles and most of them will include various explanations of terms resource and representation. To make this story short, let’s just oversimplify and say that resource is everything that’s worth mentioning. Articles is a (collection) resource. Store is a (singular, member) resource.

    Take signing in users for example. You probably already have UsersController which (by default) will allow you adding new users (create resource), deleting them (remove resource), displaying single user and also all users. If you just think in terms of data and controllers, you probably would start creating additional actions like login_user in UserController, which is a smell. If you think about resources, and that is "everything that’s worth mentioning about or creating URI for it", you might think that you need another resource, and that is: sessions. Think about this way: when user signs in, they actually create a session resource. And with sign out, you delete, remove the resource. It is much better explained in the Rails tutorial book which I recommend: http://ruby.railstutorial.org/chapters/sign-in-sign-out#sec:sessions

    To recap, this may help you in figuring out when you need new controller:

    • When you think about putting non RESTful actions in controller like log_in, calculate_date, ect.
    • When there is something that you can name and that is "interesting" enough to be a separate resource.
    • Also, when you are developing in "outside in" style, such answers come more naturally: http://rubylearning.com/blog/2010/10/05/outside-in-development/

    Overall, learning about REST and its philosophy will help a lot.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build

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.