Colin Law wrote:
> Rather than attempt to add a method to the String class, which is what
> you seem to be suggesting, You could add a method to your model that
> returns the id and name as a formatted string. So in order.rb
> something like
> def order_code
> "#{'%05d' % id} #{name}"
> end
> Then in the view just use
> <%= @order.order_code %>
Hi Colin,
Would this work if I wanted to put the leading zeros elsewhere in my app
(other views tied to other models and controllers)? Would I just
reference the Order model and then do this?
Thanks for your help,
--Matt
--
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.
No comments:
Post a Comment