views:

146

answers:

3

Rails has all sorts of auto-generated methods that I've often times struggled to find documentation for.

For example, in routes.rb, if I have:

map.resources :projects do |p|
  p.resources :tasks
end

This will get a plethora of auto-generate path and url helpers. Where can I find documentation for how to work with these paths? I generally understand how to work with them, but more explicit docs might help me understand some of the magic that happens behind the scenes.

# compare
project_path(@project)
project_task_path(@project, @task)

# to
project_path(:id => @project.id)
project_task_path(:project_id => @project.id, :id => @task.id)

Also, when I change an attribute on a model, @post.foo_changed? will be true. Where can I find documentation for this and all other magical methods that are created like this? If the magic is there, I'd love to take advantage of it.

And finally: Is there a complete resource for config.___ statements for environment.rb? I was able to find docs for Configuration#gem but what attributes can I set within the stubs like config.active_record.___, config.action_mailer.___, config.action_controller.___, etc. Again, I'm looking for a complete resource here, not just a settings for the examples I provided.

Even if you can only answer one of these questions, please chime in. These things seem to have been hiding from me and it's my goal to get them some more exposure, so I'll be upvoting all links to docs that point me to what I'm looking for.

Thanks!

ps, If they're not called auto-generated methods, I apologize. Someone can teach me a lesson here, too :)

Edit

I'm not looking for tutorials here, folks. I have a fair amount of experience with rails; I'm just looking for complete docs. E.g., I understand how routing works, I just want docs where I can read about all of the usage options.

+1  A: 

Try following command inside your application folder, this will give some helpfull informations.

$ rake routes

Also, good starting point to learn RoR : http://www.railstutorial.org/ (start directly with Rails 3 beta concept)

Riba
Riba, I know what routes are generated, but I'll still give you an upvote here because this somewhat hidden bit of information. However, I want to see the documentation for the route *methods*. E.g., `foo_path()` or `foo_url()`.
macek
+2  A: 

I'd like to find a complete reference for the available environment configuration options too. Having said that, the various environment config files are pretty well commented.

John Topley
Thanks for the `ActiveRecord::Dirty` module docs. I don't imagine these are the only magic methods generated by rails, are they? Do you know of others? `environments.rb` is well-commented, but it leaves out a lot of the specific configuration options I've sometimes seen tossed around here on SO. Where do people learn of these configuration options?
macek
ActiveRecord's attribute-based finders are dynamically generated e.g. `find_by_name_and_age` etc.Can you give a specific example of a configuration option that you've seen mentioned here that you've had trouble finding documentation for?
John Topley
I found this one: `config.action_mailer.raise_delivery_errors = true`.
macek
The `raise_delivery_errors` option is documented under the **Configuration options** section of the [ActionMailer API documentation](http://api.rubyonrails.org/classes/ActionMailer/Base.html). And I think that particular option is pretty self-documenting anyway!
John Topley
A: 

Routes screencasts, probably you will find answers there :

http://railscasts.com/episodes?search=route

Hope this will help.

(other way, very interesting site to learn RoR)

Riba
Riba, please re-read the question. I want documentation, not tutorials.
macek
Ok, sorry about that. I didn't see this kind of cheatsheets for Rails 3. If RDoc, RailsTutorials, RailsGuides does not provide you answers, I thought you have to read the sources.
Riba