Rails 3.1 - Scaffolding Files

Where can I find more information about the new syntax on these:

<%- model_class = @product.class -%>

<%=t '.title', :default => t('helpers.titles.new', :model => model_class.model_name.human, :default => "New #{model_class.model_name.human}") %>

<%= render :partial => 'form' %>

I’ve been using rails for a little bit and the “model_class = …” is all new to me, plus I can’t make sense of this:

<%=t ‘.title’, :default => t(‘helpers.titles.new’, :model => model_class.model_name.human, :default => “New #{model_class.model_name.human}”) %>

Thanks!

Esteban wrote in post #1058203:

Where can I find more information about the new syntax on these:

<%- model_class = @product.class -%>

Here the local variable model_class is assigned the value returned by the instance method class. This would be the constant identifying the class name of the instance variable @product. "Product' would most likely be the name of the class returned and stored in model_class.

I've been using rails for a little bit and the "model_class = ..." is all new to me, plus I can't make sense of this:

<%=t '.title', :default => t('helpers.titles.new', :model =>

Here you are using the "t" method (a.k.a. "Translate"). It's part of the Rails Internationalization (I18n).

Read more about the "t" method here:

Pay special attention to section 4.1.4 “Lazy” Lookup of the guide.> model_class.model_name.human, :default => "New

#{model_class.model_name.human}") %>

Here you are calling the instance method "model_name", which is defined in ActiveModel::Naming module. Using the method "human", defined in ActiveModel:Name you get a humanized version of the name of the model (i.e. "Purchase Order" instead of "PurchaseOrder").

http://api.rubyonrails.org/classes/ActiveModel/Name.html#method-i-human

Robert Walker wrote in post #1058555:

Here the local variable model_class is assigned the value returned by the instance method class. This would be the constant identifying the class name of the instance variable @product. "Product' would most likely be the name of the class returned and stored in model_class.

Sorry, I forgot to go back and fix one minor error in the above. The "class" method would return you the actual class object not the class name constant.