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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:07:17+00:00 2026-05-23T06:07:17+00:00

On my webpage, I click on a button and it makes a ajax call

  • 0

On my webpage, I click on a button and it makes a ajax call that will return a json response.

The response is like:

h = Hash.new
h['msg'] = '' # my or may not be empty
h['some_count'] = 234
h['errors'] = 0 # or 1

render :json => h.to_json

In my controller, I make a call to a model’s method that will be in charge of doing some logic and then returning these values.

Should my method return these values? Is this good practise?

def some_method(param1, param2,...)



   [ret1, ret2, ret3, msg]
end

This makes sense to me since my method makes some db calls and returns some data, and this data is only captured in this method.
If the user doesn’t have permission to do the action, it will write that error message into the msg variable which I will then display on the UI side using the json response.

Is this ok?

  • 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-23T06:07:18+00:00Added an answer on May 23, 2026 at 6:07 am

    I would say to put it in the model. The hash can be seen as part of the object/data, and as it depends on the model’s data, it would make sense to have it be part of the model.

    A common best practice of MVC is to have controllers as thin as possible (i.e. almost exclusively, if not exclusively application logic.)

    Your models however should be fat and contain most methods that deal with manipulating the data.

    Your model would then implement a method such as “getHash()” that would return the hash in whatever format you intend to use it.

    I hope this helps.

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

Sidebar

Related Questions

When users click on an element in my webpage, I would like to call
Example: The user login to the webpage => Click on a button This action
I've got a webpage that I'm working on where you click on a letter
I'm new to jQuery and Javascript. I'm trying to make a button that I
When the user clicks a button on my webpage, I call a long-running JavaScript
Does it have a magic? When I click download button on the webpage, then
I have a button in a my webpage; my expectation is when I click
What I mean is, when user click a button on a webpage, a program
In a web page button click event we need to export 2,00,000 to 5,00,000
My webpage currently looks like this: <asp:Table runat=server style=position: absolute; left: 0%; top: 82%;

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.