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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:39:29+00:00 2026-05-21T02:39:29+00:00

Ugh – not sure why I’m having so much trouble with this. Writing a

  • 0

Ugh – not sure why I’m having so much trouble with this.

Writing a simple question and answer app (see Rails – Where should this code go to stay true to MVC design? for some details)

Trying to stick to MVC principles and proper design – this app is simply a learning experience, so I want to make sure I’m doing things in a generally accepted way

The referenced question gave me advice to split up my functionality into the different models. However, trying to implement this, I find myself passing parameters all over the place and I just get a feeling that I’m not doing something right. So, here’s the basic layout of the app and the tasks I am trying to accomplish – if someone could let me know if I’m on the right track…

Question Model: contains id(pkey), question_number(int), question_text(string), answer_text(string)

User Model: contains: id(pkey), uid(string), current_question(int), name(string)

I created both of the above with scaffold so they have all the default routes, controller actions, etc…

I created a gateway controller and set it to be my default page through routes.rb

The idea is, user browses to localhost:3000/?uid=”whatever” and the index page displays the current question (Question.find_by_question_number(@user.current_question))

User enters answer in a form, which POSTs it to an action. In my first draft, this called an action in the gateway controller which checked if the answer was correct.

Now, I am trying to take vadim’s advice in my last question and keep the user login in user and the question logic in question. So now my form POSTs to the users controller.

Here’s where I get mixed up. The logic code shouldn’t be in the controller, right? So I call a method in the model, passing it stuff like the user’s answer and the question id since I can’t read the session in the model. This works fine, I can now take care of the logic in the user model – so now the user model calls a method in the question model to actually check the answer. That means I have to instantiate my question object using the ID I passed, then call another method, passing (again!) the answer. Etc…etc…

See what I mean? I definitely understand the value of MVC in theory, but whenever I try and implement it I wind up with a mess like this. It this correct, and it just seems like overcomplicating things because my program is so simple?

Can someone walk me through how you would split the logic up? You don’t need to post actual code, just what you would put where, like:

Gateway Controller:
-display question to user
-take answer and pass to XXX controller

XXX controller:
-call method Foo in XXX model, passing X and Y

The basic flow should be, user is shown a question, user answers question, answer is compared to the correct answer in the question model, message is returned based on result, and it answer was correct, user’s current_question is incremented.

Thanks so much for the help, I have books and Google and have been reading my a$$ off, just lost in the sauce here. This is my first attempt to venture outside the safety of pre-written example code, so please be gentle!!

Thanks!!

  • 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-21T02:39:29+00:00Added an answer on May 21, 2026 at 2:39 am

    The basic flow should be:

    • a method in the controller selects the question and displays a view with a form in it
    • the users submits this form
    • this is a POST to the controller
    • in the controller you check the result and display it to the user in another/the same view.

    Now to the model. You can put methods in there that check certain things. Still, the controller handles the work, it calls the method and processes the results in the controller.

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

Sidebar

Related Questions

Ugh, got this unexpected error: Argument 1 passed to QMySqliDatabaseResult::__construct() must be an instance
Ugh ok I'm terrible at explaining things, so I'll just give you the quotes
We've got two developers on the same closed (ugh, stupid gov) network, Another developer
Ugh.. mod_rewrite makes me feel stupid. I just haven't wrapped my brain around it
UGH. Hi. I have a form. I'd like to know how/if I could submit
UGH. I installed the subversion plugin for RadRails so tha I could commit changes
I need to add several hundred products to an osCommerce (ugh, I know, it
I'm using old fashioned ASP.NET validation (ugh) for a checkout process. I have a
So i've purposefully stayed away from RegEx as just looking at it kills me...ugh.
I'm trying to help out a nonprofit by doing their website. They want (ugh)

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.