jochen kaechelin
2007-May-27 15:25 UTC
problem with validates_uniqueness_of and error_messages_on
I did not get an output frpm "error_messages_for" but "validates_uniqueness_of" just works fine - I''am not able to store duplicate values for username - exactly what I want to have. Model model.rb: ----------------------------------- class Member < ActiveRecord::Base validates_uniqueness_of :username before_save :md5_password private def md5_password self.password = MD5.new(password).to_s end end register_controller.rb: ----------------------------------- class RegisterController < ApplicationController def register @m = Member.new(params[:member]) @m.save end end I render the form with a rjs file: _index.rjs ----------------------------------- page[:main].replace_html :partial => "index" Partial _index.rhtml: ----------------------------------- <% form_for :member, :url => {:action => :register } do |form| %> Error: <%= error_messages_for :member %> <p>Username <%= form.text_field :username, :size => 30 %></p> <p>Membername <%= form.text_field :membername, :size => 30 %></p> <p>Passwort <%= form.password_field :password, :size => 30 %></p> <%= submit_tag "Registrierung beantragen" %> What''s my fault?? Thanx -- Jochen Kaechelin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
lanzm
2007-May-28 10:29 UTC
Re: problem with validates_uniqueness_of and error_messages_on
what does your view render if you refactor the member in the action method like this ? @member = Member.new(params[:member]) @member.save marcel On 27 Mai, 17:25, jochen kaechelin <giss...-Vg5pTm5GbeLoK6nBLMlh1Q@public.gmane.org> wrote:> I did not get an output frpm "error_messages_for" but > "validates_uniqueness_of" just works fine - I''am not able to store > duplicate values for username - exactly what I want to have. > > Model model.rb: > ----------------------------------- > class Member < ActiveRecord::Base > validates_uniqueness_of :username > before_save :md5_password > > private > def md5_password > self.password = MD5.new(password).to_s > end > end > > register_controller.rb: > ----------------------------------- > class RegisterController < ApplicationController > def register > @m = Member.new(params[:member]) > @m.save > end > end > > I render the form with a rjs file: > > _index.rjs > ----------------------------------- > page[:main].replace_html :partial => "index" > > Partial _index.rhtml: > ----------------------------------- > <% form_for :member, :url => {:action => :register } do |form| %> > > Error: <%= error_messages_for :member %> > > <p>Username <%= form.text_field :username, :size => 30 %></p> > <p>Membername <%= form.text_field :membername, :size => 30 %></p> > <p>Passwort <%= form.password_field :password, :size => 30 %></p> > <%= submit_tag "Registrierung beantragen" %> > > What''s my fault?? > > Thanx > > -- > Jochen Kaechelin--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
jochen kaechelin
2007-May-28 10:51 UTC
Re: problem with validates_uniqueness_of and error_messages_on
lanzm schrieb:> what does your view render if you refactor the member in the action > method like this ? > > @member = Member.new(params[:member]) > @member.saveWow!!!! Now it works as expected!! Great!!! Thanx. -- Jochen --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---