Proper API doc for rails erb objects?


I recently started working with rails and maybe Im a bit spoiled coming from a Java background but is there a proper api document for the objects that are used in erb.html pages?

For example, I read a tutorial mentioning a form variable that just seem to magically exist (no idea who/where it is actually instantiated, e.g. <%= form.label :name, "Name:" %>) but what methods are available in this form object?

And what other objects, and methods, are magically available on erb.html pages?

I checked out and it does list a whole bunch of classes and methods but I have no idea what type this "form" variable is referencing.

Shahin. learning anything takes time. For example. the form in

<%= form.label :name, “Name:” %>

is called block parameter as in the following:

    <% form_for :person, :url => { :action => "update" } do |form| %>
<%= f.error_messages %>
First name: <%= form.text_field :first_name %><br />
Last name : <%= form.text_field :last_name %><br />
Biography : <%= form.text_area :biography %><br />
Admin? : <%= form.check_box :admin %><br />
<% end %>

Also, I would recommend getting a copy of “Agile Web Development with Rails 3rd edition” by Dave Thomas et al. Furthermore, I would take some time learning about the Rails API.

Good luck,


Conrad Taylor wrote:

The API ref at is the main source, but reading it sometimes requires a little more understanding.

The object passed to form_for's block is an instance of ActionView::Helpers::FormBuilder. There's not explicit documentation for it, as most of it's methods are metaprogrammed versions of the methods in ActionView::Helpers::FormHelper. FormBuilder's methods are essentially partially applied versions of FormHelper's, in that they don't require the first argument. Thus, the middle statement here:

<% form_for 'thing' do |form| %>   <%= form.text_field :name %> <% end %>

is identical to:

<%= text_field 'thing', :name %>

It's a handy shorthand, and also makes some things (rendering fields in a partial, for instance) much easier.

Going forward, there are a couple things that will help you figure out what's going on:

- object.inspect will typically get you a short string representation of an object; some objects may not show all fields here, but at least the type will be visible

- object.debug (in a view) will output a YAML version of the given object, wrapped in 'pre' tags. This can be useful for debugging models, for instance.

- if all else fails, install ruby-debug and put 'debugger' wherever needed. You can even use it inside of ERB views!

Hope this helps.

--Matt Jones

I've been finding it a little annoying as well. I'm learning Rails through "Agile Web Development with Rails 3rd edition" and I'm also picking up Ruby at the same time. This is my first web framework...and for the most part, Agile has been a great source for learning Rails. I'm in Chapter 9, where in the section where it's going through partial templates.

<%= render(:partial => "cart_item" , :collection => @cart.items) %>

This is a bit of code from it, where the book uses the method rendor() (I've been following along and writing code as I go). My question, here, is where do I find documentation for the method render?

I looked it up in the api, but when it comes to render, all it says is " render(template, local_assigns) " ... okay, template I can get, but local_assigns? What are they? I search, but can't find anything within the api about it.

Either I'm just too newbie like to get it, or there's something wrong with the rails documentation. I'd probably be closer to betting on my newbieness :stuck_out_tongue:

Thanks guys,