Infer associations/validations from existing database in Rails 3 - ruby-on-rails

Does Magic Model Generator work under Rails 3.0? I can't make it work, the install instructions that I found, doesn't help me.
Does exist an alternative to Magic Model Generator that can infer validations and associations from an existing database?
Thanx!

Looks like the MMG is abandoned -- it doesn't even work for Rails 2.3. However -- you could create a Rails 2.2 app and use it with MMG, then use the models in your Rails 3 app.
http://github.com/drnic/magic_model_generator

Related

Rails 3 vs Rails 2 pluralization issue

I am using rails 2 in my ruby on rails application.
In rails console when i try
"police".pluralize
then i get something like this:
"poluce"
I spent some time on searching this issue but haven't got proper answer.
Any clue about this ?
I tried it in Rails 3 it works fine.
This seems to be more or less a duplicate of this question:
How do I override rails naming conventions?
The key being that you can add any custom inflections that you want. To see a difference between Rails 2 and Rails 3 is not surprising. In fact, it is encouraging.

Client-Side Validation for Rails 2

Are there any client-side validation gems similar to client_side_validations (https://github.com/bcardarella/client_side_validations) for Rails 2.x?
I am actually in the process of backporting the current ClientSideValidations gem to Rails 2.x
https://github.com/bcardarella/client_side_validations-rails_2
It's not ready for public consumption yet, but you might want to keep an eye on it. It will inherit from the current gem and add the necessary functionality to Rails 2.x.
Here is a project for client side validations for rails 2, it seems to be the same project that the one you refer but it was left in order to give full functionality to rails 3. There is also an example for rails 2.
I recommend to check a great tutorial using jquery validations with rails.
Hope this helps.

Does Ruby on Rails have a way to import an existing database schema?

I know I can do a db:create and create database tables or db:migrate to a new version, however what I want to do is import the schema from an existing database (all tables) and generate models for each one.
Does ActiveRecord have the ability to do this? Thanks!
Nope. ActiveRecord is an ORM, so it doesn't have anything to do with generating database schemas or generating models. Rails doesn't have any concept of doing this, either.
You'll have to write the database migrations and do this yourself.
There's kind of a way. Create a new Rails 2.2 app (it can't be 2.3 or 3.0, the gem hasn't been updated since 2007). Then install and use the Magic Model Generator gem.
This will look at your existing database and extra all the models from it, like magic. Since the structure of basic ActiveRecord model files is pretty similar in Rails 3, you can just copy them into your current project and tweak as necessary.

Does anyone actually use Ruby On Rails scaffolding?

I think I am missing the point of scaffolding, does anyone use RoR scaffolding and if so can they point me to any specific examples of how they use it?
I am a big sass and compass fan, is it possible to incorporate this into scaffolding?
Yes, scaffolding as a generator is useful. It creates the files you need, then you customize them. I don't think anybody uses the active scaffolding anymore, I for one discourage it. But, as I said, the generator is usesful
rails g scaffold product price:float title:string description:text
as it creates the migration file, model and controller you need either way. I don't like the default tests (rspec has better test generators) as I value tests too much to have stupid autogenerated ones.
As for the sass and/or compass, I don't use generators for that, but you may try something like http://github.com/darthschmoo/rails-compass-sass-generator I don't autogenerate those as the views are always highly customized.

Why did Ruby on Rails deprecate the scaffold method

I am learning Ruby on Rails so I'm sure I'll find this out sooner or later.
Why would the scaffold method be deprecated in version 2 of Rails?
The scaffold method went against the spirit of scaffolding, which is meant to give you a starting point that you are supposed to build upon for your own needs. By generating the scaffold dynamically, there is nothing for you to edit.
The new way with the scaffold generator lets you edit the scaffolded files so you can use it to build what you actually need.
I am assuming you are referring to Dynamic Scaffolding, as the scaffold generator is still around and going strong.
David Heinemeier Hansson is on record as saying that Dynamic Scaffolding looked great in demos, but since the whole point of Dynamic Scaffolding was to teach people to use rails, abstracting it away in a single line of code was more a curse then a blessing, as no one uses Dynamic Scaffolding in production code . . . just for demos and tutorials.
If you have a copy of AWDWR handy, you can read about his whole explanation on about p81 in the latest(3rd) edition (I didn't want to copy paste).
You can still:
script/generate scaffold model_name
to generate your scaffolded model.
There is however still a Rails plugin out there that will do just what the scaffold method did before. It's called ActiveScaffold.
Because people thought it was supposed to be used for production, which would be a horrible idea. Instead you generate a scaffold which you can then easily edit and get it production ready from there.

Resources