I want to add virtual fields in a model. table: field1 field2 I want to add field3 which is field1*2 + field2 I know tihs can be achieved in View, but I want it in model. Then I will pass this model to PagerRenderer to paginate. How to achieve this? thanks -- Posted via http://www.ruby-forum.com/.
Something like the following should work just fine: class YourModel ... def field3 field1 * 2 + field2 end end As for rendering the list. It should paginate fine - but you might not be able to use the standard way of determining which columns will be rendered (I don''t think it will pick up your "virtual field"). Someone with more experience could chime in here. Cheers, Pete. On 1/13/06, Superbiji <superbiji@gmail.com> wrote:> > I want to add virtual fields in a model. > > table: field1 field2 > I want to add field3 which is field1*2 + field2 > > > I know tihs can be achieved in View, but I want it in model. > Then I will pass this model to PagerRenderer to paginate. > > How to achieve this? > > thanks > > -- > 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/20060113/f1ab5cb2/attachment.html
Superbiji wrote:> I want to add virtual fields in a model. > > table: field1 field2 > I want to add field3 which is field1*2 + field2 > > > I know tihs can be achieved in View, but I want it in model. > Then I will pass this model to PagerRenderer to paginate. > > How to achieve this? > > thanksIn your model... def field3 field1 + field2 end -- Posted via http://www.ruby-forum.com/.
Kevin Olbrich wrote:> def field3 > field1 + field2 > end@pages, @items = ctx.paginate tablename, opt I''ve did that, but my field3 does not shown in @items -- Posted via http://www.ruby-forum.com/.
Peter Sumskas wrote:> As for rendering the list. It should paginate fine - but you might not > be > able to use the standard way of determining which columns will be > renderedMy PagerRenderer is dumb renderer, which I will use for all my model. It iterates model''s columns using @items[0].class.content_columns -- Posted via http://www.ruby-forum.com/.