[Rails] Re: named_scope multiple conditions
aaah I-C. Okay thanks for clearing that up! great stuff On 16 jul, 14:16, Andy Jeffries wrote: > > Thanks for the suggestion. However what did you mean specifically with > > your last comment? > > > >> With anything like this any time you save when building up the > > conditions > > >> will be dwarfed by the time it takes to run the actual query > > Putting words in Frederick's mouth, but it simply means that it's > ridiculously quick to build up the conditions object in Ruby compared to > actually executing the SQL on the database (and communicating the SQL and > response over the socket). > > Cheers, > > Andy -- 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.
[Rails] Re: named_scope multiple conditions
Hi Fred, Thanks for the suggestion. However what did you mean specifically with your last comment? >> With anything like this any time you save when building up the conditions >> will be dwarfed by the time it takes to run the actual query On 16 jul, 13:09, Frederick Cheung wrote: > On Jul 16, 11:42 am, Jermaine wrote: > > > Hi everyone, > > > I have a working named_scope here, however it's too cluttered. > > Anyone got a better (more efficient) and concise alternative? > > > Thanks. > > well named_scope :filter, lambda {|*args| > {:conditions => {:status => args.first, :invoice_number => > args.second}.reject{|k,v| v.blank?}} > > } > > is more compact and i think does the same thing as your code. With > anything like this any time you save when building up the conditions > will be dwarfed by the time it takes to run the actual query > > Fred > > > > > > > named_scope :filter, lambda { |*args| > > if > > args.first && args.second == nil > > {} # return all records > > > if args.first.blank? > > { :conditions => ["status = ?", args.second] } > > > if > > args.second.blank? > > { :conditions => ["invoice_number= ?", args.first] } > > > else > > { :conditions => ["nvoice_number= ? and status = ?", > > args.first, args.second] } > > end > > end > > end > > } -- 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.
[Rails] named_scope multiple conditions
Hi everyone, I have a working named_scope here, however it's too cluttered. Anyone got a better (more efficient) and concise alternative? Thanks. named_scope :filter, lambda { |*args| if args.first && args.second == nil {} # return all records if args.first.blank? { :conditions => ["status = ?", args.second] } if args.second.blank? { :conditions => ["invoice_number= ?", args.first] } else { :conditions => ["nvoice_number= ? and status = ?", args.first, args.second] } end end end } -- 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.
[Rails] Re: Howto Overwrite existing Ruby Class via Rails app?
No that's not the problem, in fact I'am using I18n. But that only works for translating /localizing your data from the database. But now I'm trying to Post data to the database. So for instance, if I would have a form with a text field: date_attended (<%= f.text_field :date_attended%> and would post the following 'SPANISH' date to the database: 10 Abril 2009 (-> which is April 10, 2009 in English) The database won't understand this. So therefore I need to change this file: 1.8/usr/lib/ruby/1.8/date/ format.rb, because when I do that it works, but I want to do it via my rails app. I want to overwrite it there, but have no idea how. I was also thinking of maybe translating the months in the model itself, so that the database understands which month I'm talking about. But also I have no idea how to implement this in my code. I need (code)samples/ guidance, any suggestion is welcome. On May 31, 11:19 pm, Maurício Linhares wrote: > Look for Rails i18n helpers, they do what you're looking for. > > - > Maurício Linhareshttp://alinhavado.wordpress.com/(pt-br) > |http://blog.codevader.com/(en) > > On Sun, May 31, 2009 at 5:54 PM, Jermaine wrote: > > > Hello Everyone, > > > in the 1.8/usr/lib/ruby/1.8/date/format.rb file there is the following > > code: > > > --- > > --- > > class Date > > > module Format # :nodoc: > > > MONTHS = { > > 'january' => 1, 'february' => 2, 'march' => 3, 'april' => > > 4, > > 'may' => 5, 'june' => 6, 'july' => 7, 'august' => > > 8, > > 'september'=> 9, 'october' =>10, 'november' =>11, 'december' > > =>12 > > } > > --- > > --- > > > How can I "overwrite" these values via my rails app? I'm trying to > > submit a foreign date to the database, so I want to overwrite > > (translate) this piece out of the format.rb file in my rails app, so > > that it understands which month I'm talking about. > > > Any suggestions/tips how I can fix this in a smart/efficient way? > > > Many Thanks in advance! --~--~-~--~~~---~--~~ 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-talk@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 -~--~~~~--~~--~--~---
[Rails] Howto Overwrite existing Ruby Class via Rails app?
Hello Everyone, in the 1.8/usr/lib/ruby/1.8/date/format.rb file there is the following code: -- class Date module Format # :nodoc: MONTHS = { 'january' => 1, 'february' => 2, 'march'=> 3, 'april'=> 4, 'may' => 5, 'june' => 6, 'july' => 7, 'august' => 8, 'september'=> 9, 'october' =>10, 'november' =>11, 'december' =>12 } -- How can I "overwrite" these values via my rails app? I'm trying to submit a foreign date to the database, so I want to overwrite (translate) this piece out of the format.rb file in my rails app, so that it understands which month I'm talking about. Any suggestions/tips how I can fix this in a smart/efficient way? Many Thanks in advance! --~--~-~--~~~---~--~~ 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-talk@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 -~--~~~~--~~--~--~---
[Rails] how to transform data to database (translation -> i18n)
Hi Everyone, I'm using I18n in my rails app and I'm very pleased about it. However, I'm now having problems posting Date objects to the database. The problem is that in my text field the date is represented in Dutch. So for example: I have a text field: <%= f.calender_date_select: date_attended %> Where I fill in a date like: 26 oktober 2009 Now the database won't recognize this, and that's probably because he's posting a foreign language to the database which he doesn't understand. I'm guessing I should translate each month somewhere (in the model??) like this: Januari => January Februari => Februari Maart => March etc.. etc.. Any suggestions?? Many thanks in advance. --~--~-~--~~~---~--~~ 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-talk@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 -~--~~~~--~~--~--~---