Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

ruby - Error during Rails multi sort_by when hitting empty date value -


sorry newb question, everyone. here is:

i have hash looks this:

{ "id" => { :task => [ { :due => mon dec 20 00:00:00 utc 2010, completed: => "2010-12-18t17:29:57z", :priority => "1", ... } ] , ... } , ... } 

to sort this, use:

tasks = hash.with_indifferent_access  tasks.sort_by { |k,v| [ v['task'][0]['completed'], v['task'][0]['due'], v['task'][0]['priority'] ] } 

this works fine long :due has date value. when doesn't have date value, permitted, looks this:

:due => "" 

then rails error saying: "comparison of array array failed."

i tried putting in ternary , other logic default distant date if :due empty, seems isn't possible in sort_by block.

any ideas how lick one? many thanks!

here example assuming "due" string , when empty want sort before other tasks same completion value. idea convert both valid dates empty strings same comparable data type (in case integer number of seconds since epoch). have intentionally ignored details of setup irrelevant question.

# required time.parse require 'time'  tasks = [   {     completed: "2010-12-18t17:29:57z",     due:       "mon dec 20 00:00:00 utc 2010",     priority:  "1"   },{     completed: "2010-12-18t17:29:57z",     due:       "mon dec 20 00:00:00 utc 2010",     priority:  "2"   },{     completed: "2010-12-18t17:29:57z",     due:       "",     priority:  "1"   },{     completed: "2010-12-17t17:29:57z",     due:       "mon dec 20 00:00:00 utc 2010",     priority:  "1"   },{     completed: "2010-12-19t17:29:57z",     due:       "mon dec 20 00:00:00 utc 2010",     priority:  "1"   } ]  require 'pp' pp tasks.sort_by{ |h| [   time.parse(h[:completed]),   h[:due].empty? ? 0 : time.parse(h[:due]).to_i,   h[:priority].to_i ]} #=> [{:completed=>"2010-12-17t17:29:57z", #=>   :due=>"mon dec 20 00:00:00 utc 2010", #=>   :priority=>"1"}, #=>  {:completed=>"2010-12-18t17:29:57z", :due=>"", :priority=>"1"}, #=>  {:completed=>"2010-12-18t17:29:57z", #=>   :due=>"mon dec 20 00:00:00 utc 2010", #=>   :priority=>"1"}, #=>  {:completed=>"2010-12-18t17:29:57z", #=>   :due=>"mon dec 20 00:00:00 utc 2010", #=>   :priority=>"2"}, #=>  {:completed=>"2010-12-19t17:29:57z", #=>   :due=>"mon dec 20 00:00:00 utc 2010", #=>   :priority=>"1"}] 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -