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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:47:50+00:00 2026-06-07T15:47:50+00:00

I am just getting started with Ruby on Rails and i am not sure

  • 0

I am just getting started with Ruby on Rails and i am not sure how i should do the queries to database in order to get data, add data or edit data…

Is it better to find for example a user from the controller or its better to add the queries into the model?

currently, my user homepage controller looks like this with some simple functionality

class HomeController < ApplicationController

  #get current_user variable
  helper_method :current_user

  def index
    if user_signed_in?
        @user = User.find_by_id(current_user.id)
    else
        render_404
    end
  end
end

it simply checks if the user is logged in and finds the user…

Should i move the db calls to a model for best practice or using the above method is also fine?

  • 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-06-07T15:47:52+00:00Added an answer on June 7, 2026 at 3:47 pm

    The way you did it is fine in my opinion. The controller’s job is to set the data for the view and part of setting the data is fetching it from the DB.

    For more complex DB query you could use scope which are located in the model. This way the controller does not hold too much logic of DB queries on the model.

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

Sidebar

Related Questions

I am getting started with a non-SQL database (specifically, MongoDB) and Ruby on Rails
I'm just getting started with rails and ruby and i wanna start giving back
I am just getting started with Rails 3 and I do not quite understand
I'm just getting started with Ruby on Rails development and I have a question
I'm just getting started with Ruby and Ruby on Rails, so excuse me if
I'd just started toying around with Ruby on Rails and had come across an
just getting started with Rails, I would like to consume a webservice (using ActiveResource)
Just getting started with OpenFrameworks and I'm trying to do something that should be
I am just getting started with flex and am using the SDK (not Flex
Learning Ruby and Rails. In following the getting started guide if I invoke rails

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.