Jump to content

The ultimate community for Ruby on Rails developers.


A couple basic questions about rails

  • Please log in to reply
3 replies to this topic

#1 behrooz66



  • Members
  • 2 posts

Posted 26 November 2013 - 06:18 PM

Hola friends!


So I have recently started to Ruby on Rails and as I have had some previous experience with Yii Framework, I faced some stuffs that are done completely differently (and to me, backwards!) in rails which I wanted to make sure if those are the right way of doing things.


So for example in Yii (and also some other frameworks) the overall idea is to generate an application off of a database. In Rails, it looks like the idea is to create database off of the application! I mean here in Rails, you define each model first and then the corresponding table in the database is created based on it. Everytime you need to modify a table, you have write a small script file in Rails and then run it to apply the modification on your tables.


This raises a couple questions for me:

1. Why?! I mean doesn't it make the database design & relationship management much more complicated than it needs to be? Isn't it not practical for really large databases with very complicated relationships?

2. Is is necessary to go that way? Is there any way in Rails to not go backwards?!

3. What's the advantage of this approach?



Putting that aside, my second question is about the login feature. In many frameworks it is an embedded feature once you create your application. Does Rails provide something alike?


P.S: Thanks in advance for your kind answers. I will come up with some more dumb questions as I move forward!

#2 Kelli Shaver

Kelli Shaver


  • Administrators
  • 76 posts
  • LocationKentucky

Posted 27 November 2013 - 03:03 AM

There's no reason you have to use ActiveRecord migrations, though your life will be a lot easier if you do. If you're working from an existing database, for example, it's not necessary.


This isn't specific to Rails. Any ruby app using the ActiveRecord gem (Sinatra + Sinatra-ActiveRecord, for instance) can use database migrations. Several PHP frameworks and ORMs (e.g. Symfony/Doctrine, Laravel) support database migrations, as well. 


As to the benefits, migrations let you manage and evolve your databases schema over the lifecycle of your application. It basically gives you the ability to programmatically make incremental database changes. This also means you can automate database upgrades for deployment via Rake tasks, or as tasks in your deployment script of choice.


I mean doesn't it make the database design & relationship management much more complicated than it needs to be? Isn't it not practical for really large databases with very complicated relationships?



Actually, it does quite the opposite. Manually managing a large and complex database schema can be difficult.  Migrations help maintain database integrity and give you rollback options.

#3 stevieing



  • Members
  • 40 posts

Posted 27 November 2013 - 11:14 AM

Good questions. There are a lot of people that will tell you that Rails is not backwards and designing your application from the top down is a better way to do it.


If you need to create a feature you will describe your feature, write tests for that feature and then implement that feature. The models and attributes will come out of that which means that you will only be writing code that you need. This has the advantage of reducing complexity and speeding up development.


If you design your database first then you will have to guess at the tables and attributes you need, you will inevitably get it wrong and have to go back.


Using Object Relational Mapping (ORM) is a much better way to manage databases as it is technology agnostic which means you can use any database. Once you get used to it you will find it is much easier to manage and far less complex. When somebody first mentioned it to me I thought it was a crazy idea!


In Rails for specific features there are gems (libraries). So for the login there are gems such as Devise. Again this is advantageous as you will only be adding functionality that is necessary. Rails has a rich set of gems available. Not everybody needs login embedded as standard.



#4 behrooz66



  • Members
  • 2 posts

Posted 27 November 2013 - 08:46 PM

Thanks to both of you guys. I appreciate your time & answers. I got what I was searching for.


As I'm moving forward, I will probably come up with more basic questions and I will try to buy you guys later :-P

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users