Where can I find more information about the new syntax on these:
<%- model_class = @product.class -%>
<h1><%=t ''.title'', :default =>
t(''helpers.titles.new'', :model =>
model_class.model_name.human,
:default => "New
#{model_class.model_name.human}") %></h1>
<%= 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!
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/eGAp5qbZVWYJ.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
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. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.