Does anyone actually use Ruby On Rails scaffolding? - ruby-on-rails

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.

Related

Rails generate scaffold creates blank controller

The last couple of times that I've used 'rails generate scaffold [ModelName]' everything has been generated except that the controller is blank. It contains no methods at all. It's easy enough to copy that in from other sources, but I'm wondering what is going on.
The only unique thing about this application for me is that it's using the ActiveAdmin gem.
Any suggestions for how I could get this working as expected again?
+1 to hajpoj, but there are a couple additional steps you could use to troubleshoot.
What does rails generate scaffold_controller give you? My first suggestion to be to isolate the controller generator and go from there.
Following that, I would actually look in the Rails generator code at the point of controller generation and work backwards from there. Here is (I believe) the entry point, from there, you can follow the code to where things are failing. This is, obviously, not the easiest path, but would probably teach you a lot about the rails internals.

What is the difference between default scaffold and nifty:scaffold?

I am trying to generate a layout which I can use between my rails webapp and mobile versions. I have been using nifty-generator, but it says the generated files are identical to what was generated by rails3 new application creation.
What's the major difference between default scaffold and nifty:scaffold?
If you visit the Github page (https://github.com/ryanb/nifty-generators) for the project under 'Troubleshooting and FAQs' it answers a few questions including this one. The response given there is:
One of the primary differences is that nifty:scaffold allows you to
choose which controller actions to generate.
rails g nifty:scaffold post name:string index new edit
There are a few changes to the generated code as well, such as no XML
format by default.
It also offers support for HAML, Shoulda, and RSpec.
Once you get a handle on the code that Rails needs in its RESTful controllers I would highly recommend using Inherited Resources (https://github.com/josevalim/inherited_resources) instead. It really helps DRY up your controllers.

Is it possible to add globalize3 to an external ActiveRecord model class?

I have a project for which I'm using the globalize3 gem to allow for multiple languages. In my own models I just add 'translates field1, field2, etc.' and the appropriate migrations and it is all working great.
The problems is that I also have some functionality that depends on external gems. For some of those models I would like to add globalize too. I don't have the code for the models to modify directly like I did with the others. Reopening the model doesn't seem to work. Is there a way to add that translates line to models that I don't have direct access to ?
I'm using Rails 3.1 and Ruby 1.9.2 in case it matters.
Could you supply the name of the gem and a model from that gem?
Are the classes namespaced under a module? If so, you may not be re-opening the classes correctly. I use the qwandry gem to examine gems that I've included in my project, so that might be helpful in determining this. Of course looking at the source on the project's site is also good if it's available.
I assume that what happens when you say it isn't working is that the I18n.locale setting doesn't affect setting/getting the fields, correct? It would probably complain about there not being a table if it was working but you hadn't yet created the tables.

A tool to automatically generate a UML diagram for a Rails Application

Looking for a good tool/gem that can automatically generate a nice looking UML diagram for an existing rails application.
(Im imagining such a tool would read the schema.rb file and then scan the models for relationships)
For Rails 3, try Railroady, it's maintained as well.
You could try Rails ERD as a an alternative to Railroad. It is maintained and works specifically for Rails 3.
RubyMine has a tool to do this; they call it a "model dependency diagram", but it generates a UML-like graph for your application models.
If you don't want to use RubyMine, check out RailRoad. It's a standalone tool that does similar, though RubyMine's is prettier, IMO.

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