PalaniKannan K wrote in post #957235: > > I tried > def author_yr > "#{self.author_year.last(4)}" > end. > > But it shows "Undefined local variable or method 'author_yr'" > > when i use author_yr in find by > > ":order => ["author_year like = ?", author_yr]". Please suggest me some > idea > in ordering.
> Palani Kannan. K, Impossible. You're defining author_yr in a ruby model, but expecting the DATABASE to know what that is. Doesn't work that way. As Fred mentioned, you need to use a database function that looks at the "author_year" field (the last 4 characters) to order upon. Look in the manuals for whatever DB engine you're using for string functions. That's what goes in the :order => [] -- 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-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.