On 29 November 2010 20:30, turkan <kai.schl...@googlemail.com> wrote: > Hi. > > I am often checking the same parameters (like param[:page] and > param[:per_page]) in models over and over again (are those in a > specific range ... if not use defaults): > page = !options[:page].blank? && options[:page] =~ /^[0-9]+$/ && > options[:page].to_i > 0 ? options[:page].to_i : 1 > per_page = !options[:per_page].blank? && options[:per_page] =~ /^[0-9]+ > $/ && options[:per_page].to_i > 0 && options[:per_page].to_i <= 100 ? > options[:per_page].to_i : 10 > > How can I make this more DRY and easier to read?
You can make it easier to read by using simpler constructs such as if. It will take up a few more lines of source code but will not have any measurable effect on execution time, and will be much easier for those that come after you to understand. You can DRY it by putting it in a method. I also have to wonder why a _model_ is worrying about page number and per_page. 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-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.