Alex MacCaw
2006-Apr-22 13:07 UTC
[Rails] Newbie question about using helpers in controllers
I''m trying to display a list of pages in xml. I want to change page.update_at to distance_of_time_in_words_to_now. However whenever I run it I get an error saying: undefined method `distance_of_time_in_words_to_now'' I know I can just go the rails api and copy the source, but there must be another way. def list @page = Page.find(:all, :order => "updated_at desc") for page in @page page.updated_at = distance_of_time_in_words_to_now(page.updated_at) end render :xml => @page.to_xml end -- Posted via http://www.ruby-forum.com/.
D. Taylor Singletary
2006-Apr-22 15:10 UTC
[Rails] Newbie question about using helpers in controllers
This should help you out. It has its limitations but for most purposes it''s what you are looking for. Especially useful for chaining helpers in an action in your controller. http://www.bigbold.com/snippets/posts/show/1799 D. Taylor Singletary, Reality Technician On 4/22/06, Alex MacCaw <maccman@gmail.com> wrote:> > I''m trying to display a list of pages in xml. I want to change > page.update_at to distance_of_time_in_words_to_now. However whenever I > run it I get an error saying: > undefined method `distance_of_time_in_words_to_now'' > I know I can just go the rails api and copy the source, but there must > be another way. > > def list > @page = Page.find(:all, :order => "updated_at desc") > > for page in @page > page.updated_at = distance_of_time_in_words_to_now(page.updated_at) > end > > render :xml => @page.to_xml > end > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060422/d123a015/attachment.html