Ruby on Rails Tuesday, June 1, 2010

On 1 June 2010 16:18, Matt Royer <lists@ruby-forum.com> wrote:
> Peter Hickman wrote:
>> you could create a method called
>>
>> def leading_zeros(number)
>>   "%05d" % number
>> end
>>
>> and then call it
>>
>> "#{leading_zeros order.id}#{order.name}"
>>
>
> Thanks Peter!
>
> I put the method in the application_helper.rb file:
>
> ----
>    def leading_zeros(number)
>      "%05d" % number
>    end
> ----
>
> And then put the following like you said:
>
> ----
> #{leading_zeros order.id} #{order.name}"

You have a missing " on the front, but that may just be an copy/paste error

> ----
>
> It's giving me this error when I refresh my view:
>
> ----
> NoMethodError in Orders#index
> Showing app/views/orders/index.html.erb where line #9 raised:
>
> undefined method `leading_zeros' for "00009":String

Are you sure line 9 of that file is the one you have shown above?
Have you remembered to save the file?

Colin

--
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