I have an application that makes a render inline, and another in XML based on data from an URL. I need to validate the data before passing it over to SQL, and I would like to receive the errors in the returned array, or at least a TRUE/FALSE. As there is no associated view file I don’t know how to... Could someone help me out or orientate me in some way? Regards and thanks, Daniel. -- 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Can you give an example of what you mean by "validate the data before passing it over to SQL"? If it''s SQL injection you''re worried about, rails can help clean up user input, but I''m not sure that''s where your heading with this... On Feb 2, 11:18 am, Daniel López <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I have an application that makes a render inline, and another in XML > based on data from an URL. > I need to validate the data before passing it over to SQL, and I would > like to receive the errors in the returned array, or at least a > TRUE/FALSE. As there is no associated view file I don’t know how to... > > Could someone help me out or orientate me in some way? > > Regards and thanks, > > Daniel. > -- > Posted viahttp://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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Harold wrote:> Can you give an example of what you mean by "validate the data before > passing it over to SQL"? > > If it''s SQL injection you''re worried about, rails can help clean up > user input, but I''m not sure that''s where your heading with this... > > > > On Feb 2, 11:18�am, Daniel L�pez <rails-mailing-l...@andreas-s.net>SQL Injection, mmm... yes, maybe, but I refer particularly to check if a string is numeric, date type or too short for the database values (for example). Only if these requirements are OK, the select query is executed. Otherwise, the application should return false or something. Thanks in advance, Harold. ;) -- 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Harold A. Giménez Ch.
2009-Feb-02 17:18 UTC
Re: ActiveRecord can validates "select" querys?
Sounds like something you can do with ActiveRecord validations: http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html for example: validates_numericality_of :some_numer validates_length_of :something_else, :in => 3..12 You can use validate_format_of :a_date (and specify a regex), or there''s a plugin that helps for this (i haven''t tried it: http://railslodge.com/plugins/111-validates-date-time) etc... is that what you''re looking for? On Mon, Feb 2, 2009 at 12:10 PM, Daniel López < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Harold wrote: > > Can you give an example of what you mean by "validate the data before > > passing it over to SQL"? > > > > If it''s SQL injection you''re worried about, rails can help clean up > > user input, but I''m not sure that''s where your heading with this... > > > > > > > > On Feb 2, 11:18�am, Daniel L�pez <rails-mailing-l...@andreas-s.net> > > SQL Injection, mmm... yes, maybe, but I refer particularly to check if a > string is numeric, date type or too short for the database values (for > example). > > Only if these requirements are OK, the select query is executed. > Otherwise, the application should return false or something. > > Thanks in advance, Harold. ;) > -- > 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Harold A. Giménez Ch. wrote:> Sounds like something you can do with ActiveRecord validations: > > http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html > > for example: > > validates_numericality_of :some_numer > validates_length_of :something_else, :in => 3..12 > > You can use validate_format_of :a_date (and specify a regex), or there''s > a > plugin that helps for this (i haven''t tried it: > http://railslodge.com/plugins/111-validates-date-time) > > etc... > > is that what you''re looking for?No... ActiveRecord validations only works if the SQL operation is an insert or update ("create" and "update" methods, respectively), but I also need it to select querys ("find" method). That''s the problem... :S Thanks again! ;) -- 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Harold A. Giménez Ch.
2009-Feb-02 17:42 UTC
Re: ActiveRecord can validates "select" querys?
In that case, I don''t know of a way to reuse an ActiveRecord validation before running a find. You don''t even have a ActiveRecord object at that point yet. You might just have to write your custom validations before running the find. Maybe someone else has a better option. Sorry :-o) -H On Mon, Feb 2, 2009 at 12:30 PM, Daniel López < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Harold A. Giménez Ch. wrote: > > Sounds like something you can do with ActiveRecord validations: > > > > > http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html > > > > for example: > > > > validates_numericality_of :some_numer > > validates_length_of :something_else, :in => 3..12 > > > > You can use validate_format_of :a_date (and specify a regex), or there''s > > a > > plugin that helps for this (i haven''t tried it: > > http://railslodge.com/plugins/111-validates-date-time) > > > > etc... > > > > is that what you''re looking for? > > No... ActiveRecord validations only works if the SQL operation is an > insert or update ("create" and "update" methods, respectively), but I > also need it to select querys ("find" method). That''s the problem... :S > > Thanks again! ;) > -- > 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Why do you need to validate on a find method? There should never be an invalid record at the database, that''s why there is no validation in a find and for the same reason there shouldn''t be. If you think you really need it, maybe you haven''t really figured out what your problem is. - Maurício Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) On Mon, Feb 2, 2009 at 2:42 PM, Harold A. Giménez Ch. <harold.gimenez-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In that case, I don''t know of a way to reuse an ActiveRecord validation > before running a find. You don''t even have a ActiveRecord object at that > point yet. > > You might just have to write your custom validations before running the > find. Maybe someone else has a better option. Sorry :-o) > > -H > > On Mon, Feb 2, 2009 at 12:30 PM, Daniel López > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> >> Harold A. Giménez Ch. wrote: >> > Sounds like something you can do with ActiveRecord validations: >> > >> > >> > http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html >> > >> > for example: >> > >> > validates_numericality_of :some_numer >> > validates_length_of :something_else, :in => 3..12 >> > >> > You can use validate_format_of :a_date (and specify a regex), or there''s >> > a >> > plugin that helps for this (i haven''t tried it: >> > http://railslodge.com/plugins/111-validates-date-time) >> > >> > etc... >> > >> > is that what you''re looking for? >> >> No... ActiveRecord validations only works if the SQL operation is an >> insert or update ("create" and "update" methods, respectively), but I >> also need it to select querys ("find" method). That''s the problem... :S >> >> Thanks again! ;) >> -- >> 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Harold A. Giménez Ch.
2009-Feb-02 17:47 UTC
Re: ActiveRecord can validates "select" querys?
Completely agree with you, Mauricio. The only reason I can see the need to validate before a find is if your are absolutely obsessed with performance and you don''t want to hit the DB if you know a priori that no record will be returned. This is definitely not a normal case. If the query takes too long you might have to rethink your schema, your query, or create proper indexes. On Mon, Feb 2, 2009 at 12:44 PM, Maurício Linhares < mauricio.linhares-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Why do you need to validate on a find method? > > There should never be an invalid record at the database, that''s why > there is no validation in a find and for the same reason there > shouldn''t be. If you think you really need it, maybe you haven''t > really figured out what your problem is. > > - > Maurício Linhares > http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) > > > > On Mon, Feb 2, 2009 at 2:42 PM, Harold A. Giménez Ch. > <harold.gimenez-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > In that case, I don''t know of a way to reuse an ActiveRecord validation > > before running a find. You don''t even have a ActiveRecord object at that > > point yet. > > > > You might just have to write your custom validations before running the > > find. Maybe someone else has a better option. Sorry :-o) > > > > -H > > > > On Mon, Feb 2, 2009 at 12:30 PM, Daniel López > > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > >> > >> Harold A. Giménez Ch. wrote: > >> > Sounds like something you can do with ActiveRecord validations: > >> > > >> > > >> > > http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html > >> > > >> > for example: > >> > > >> > validates_numericality_of :some_numer > >> > validates_length_of :something_else, :in => 3..12 > >> > > >> > You can use validate_format_of :a_date (and specify a regex), or > there''s > >> > a > >> > plugin that helps for this (i haven''t tried it: > >> > http://railslodge.com/plugins/111-validates-date-time) > >> > > >> > etc... > >> > > >> > is that what you''re looking for? > >> > >> No... ActiveRecord validations only works if the SQL operation is an > >> insert or update ("create" and "update" methods, respectively), but I > >> also need it to select querys ("find" method). That''s the problem... :S > >> > >> Thanks again! ;) > >> -- > >> 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The fact is that the project I''m developing is a database connection API and, although is not essential, it would be nice that it could checks the data integrity. The reason for do that is to improve the user (or programmer :P) experience and prevent potential errors in the final application, not the performance. Anyway, I found a plugin that does what I want, but it has no associated download :S. Here''s a brief description (in Spanish): http://www.tabernadelturco.com/2006/05/03/validacion-de-datos-en-controladores-sin-modelo-asociado-con-ruby-on-rails/ Does anyone know where can I find it? This is the original link in RubyForge: http://rubyforge.org/projects/validator Thanks again guys! :) -- 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---