Neil Cauldwell
2008-Sep-20 12:18 UTC
Preventing users from using your app name in their name
Is there a Rails validation helper or an easy way of preventing attributes from containing a certain word match, e.g. you have a User model, the user has a name attribute, and you don''t want the @user.name to == ''MyRailsApp'' or to have ''MyRailsApp'' somewhere in there? I imagine it would look something like this (although I can''t get this one to work - it always fails); validates_format_of :name, :with => /!MyRailsApp/i, :message => "You can''t use our Website name." Any ideas? -- 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 -~----------~----~----~----~------~----~------~--~---
Erol Fornoles
2008-Sep-20 15:26 UTC
Re: Preventing users from using your app name in their name
On Sep 20, 8:18 pm, Neil Cauldwell <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Is there a Rails validation helper or an easy way of preventing > attributes from containing a certain word match, e.g. you have a User > model, the user has a name attribute, and you don''t want the @user.name > to == ''MyRailsApp'' or to have ''MyRailsApp'' somewhere in there? > > I imagine it would look something like this (although I can''t get this > one to work - it always fails); > > validates_format_of :name, :with => /!MyRailsApp/i, :message => "You > can''t use our Website name." > > Any ideas? > -- > Posted viahttp://www.ruby-forum.com/.Try this one: validates_each :name do |record, attr, value| record.errors.add attr, "can''t use our Website name." if value =~ / MyRailsApp/i 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-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 -~----------~----~----~----~------~----~------~--~---
Phillip Koebbe
2008-Sep-20 15:34 UTC
Re: Preventing users from using your app name in their name
Neil Cauldwell wrote:> > Any ideas?Try validates_exclusion_of http://www.railsbrain.com/api/rails-2.1.0/doc/index.html?a=M001745&name=validates_exclusion_of Peace. -- 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 -~----------~----~----~----~------~----~------~--~---
Neil Cauldwell
2008-Sep-20 15:43 UTC
Re: Preventing users from using your app name in their name
Erol Fornoles wrote:> On Sep 20, 8:18�pm, Neil Cauldwell <rails-mailing-l...@andreas-s.net> > wrote: >> >> Any ideas? >> -- >> Posted viahttp://www.ruby-forum.com/. > > Try this one: > > validates_each :name do |record, attr, value| > record.errors.add attr, "can''t use our Website name." if value =~ / > MyRailsApp/i > endThat one works great, thanks. -- 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 -~----------~----~----~----~------~----~------~--~---
Neil Cauldwell
2008-Sep-20 15:44 UTC
Re: Preventing users from using your app name in their name
Phillip Koebbe wrote:> Neil Cauldwell wrote: >> >> Any ideas? > > Try validates_exclusion_of > > http://www.railsbrain.com/api/rails-2.1.0/doc/index.html?a=M001745&name=validates_exclusion_of > > Peace.Thanks, Phillip. I found validates_exclusion_of soon after posting but, I couldn''t make it case sensitive. -- 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 -~----------~----~----~----~------~----~------~--~---