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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:54:01+00:00 2026-05-12T19:54:01+00:00

After working with ASP.Net MVC, it has me thinking about Rails. I worked with

  • 0

After working with ASP.Net MVC, it has me thinking about Rails. I worked with Rails prior, but am a little rusty. ASP.Net MVC tutorials recomment hiding data layer implementation with the repository pattern. This allows easiesr Dependency Injection for Unit Testing, and nice decoupling of the controller from the model implementation.

I remember Rails’ controllers using Active Record objects directly, and unit tests using test databases that could be setup and torn down with ease. That solves the need to swap out for unit testing, but still it seems like a bad idea to have so much ActiveRecord code exposed in the controller.

So my question is, what is the latest best practice here? Are real (not mocked) databases still used for unit testing? Do Rails developers call ActiveRecord directly, or an abstraction?

  • 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-12T19:54:01+00:00Added an answer on May 12, 2026 at 7:54 pm

    Does ActiveRecord even really constitute the “data layer”, I wonder? After all, its purpose is to abstract (to a fairly reasonable extent) the actual interaction storage. If I have a model that inherits from ActiveRecord::Base and I reference that model in a controller, am I really interacting with the data layer?

    Looking at a brief description of the Repository Pattern I’d say that methods of the find_by_ are already giving you much of what it describes, which is good, isn’t it? OK, the abstraction layer is leaky (one might more generously say “pragmatic”) in that we can go a lot closer to the metal if need be, and find_by_sql for example will pretty much make it obvious that we’re dealing with a relational database of some kind.

    I’d recommend never (or maybe I should say “rarely and not without extreme justification” – it’s always tricky using absolutes) putting code in controllers that makes it possible to infer the data platform being used. It should all be pushed into the models – named_scope can be very useful here. For complex results, consider using “presentation” objects as the interface (Struct and my personal favourite OpenStruct can be very useful here).

    While ActiveRecord is the de facto standard, given that it installs with Rails, it’s not the only game in town. For non-SQL databases, something different is necessary, but even in the SQL domain there’s Datamapper (is that based on the eponymous PoEAA pattern?)

    In Rails 3.0 it’s going to be a lot easier to pick and choose components such as the ORM as Yehuda and the boys unpick and clean up the interfaces.

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

Sidebar

Related Questions

I've been working on an ASP.NET MVC project for about 8 months now. For
I'm working on an ASP.NET MVC 2 / .NET 3.5 project which includes SSRS
I'm working on an ASP.NET MVC 2 application and use a seperate class library
I've been spending the past several weeks working on my asp.net mvc site following
Im working on a web project in ASP .NET MVC 2. In this project
With an ASP.NET MVC project I'm working on, I am required to check whether
I've been working on an ASP.NET MVC 2 (.NET 4.0, Visual Studio 2010) application
After pushing my asp.net mvc (with spark view engine) project to our live server
So far I've been using ASP.NET MVC 3 BETA. Everything was working fine till
After working with .NET's HttpWebRequest / Response objects, I'd rather shoot myself than use

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.