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 %>
Username <%= form.text_field :username, :size => 30 %>
Membername <%= form.text_field :membername, :size => 30 %>
Passwort <%= form.password_field :password, :size => 30 %>
<%= submit_tag "Registrierung beantragen" %>What’s my fault??
Thanx
–
Jochen K.