[Rails] Using session data in model

Johan Allard johan at allard.nu
Mon Feb 28 03:18:33 GMT 2005


Hi,

I want to use my some session data when I validate som data in the 
model. The specific problem I have is that I present different forms 
data based on gender, and then dependent of the gender, there's 
different fields that needs validation. I'm wondering what's the 
preffered way of doing this. The session data is not present in the 
model, i.e:

class Myclass < ActiveRecord::Base
	belongs_to :member

	def validate
		errors.add_on_empty %w{ required_field } if @session["member"].gender 
== 'm'
	end
end

does not work since the @session["member"] variable is not set. I've 
tried to set:

@member = @session["member"]

in my controller before I call Myclass.save and that doesn't seem to 
work either. So how should this be handled?

Best regards

//johan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
Url : http://one.textdrive.com/pipermail/rails/attachments/20050228/3357d50e/PGP.bin


More information about the Rails mailing list