Thursday, April 26, 2012

[Rails] Re: Rails 3.1 - Scaffolding Files

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:
http://guides.rubyonrails.org/i18n.html#overview-of-the-i18n-api-features

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/Naming.html#method-i-model_name
http://api.rubyonrails.org/classes/ActiveModel/Name.html#method-i-human

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate