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 %>

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.

what does your view render if you refactor the member in the action
method like this ?

   @member = Member.new(params[:member])
   @member.save

marcel

lanzm schrieb:

what does your view render if you refactor the member in the action
method like this ?

   @member = Member.new(params[:member])
   @member.save

Wow!!! Now it works as expected!!
Great!!! Thanx.


Jochen

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs