On Saturday, April 5, 2014 2:25:32 AM UTC-7, ar wrote:
>
> Hi, I'm new to sequel (and ActiveRecord, too).
>
> I have a User class, when saving, validates some columns.
>
> here's my code
>
>
>
> # -*- encoding: binary -*-
>
> require 'rubygems'
> require 'bundler'
>
> Bundler.require(:default, :development)
>
> DB = Sequel.connect("sqlite:///tmp/a.db")
>
> # DB.create_table(:users) do
> # primary_key :id
> # String :username, :null => false
> # String :email, :null => false
> # String :password_hash, :null => false
> # String :salt, :null => false
> # end
>
> class User < Sequel::Model
> plugin :validation_helpers
>
> # attr_accessible :password, :password_confirmation
> set_allowed_columns :password, :password_confirmation
> attr_accessor :password, :password_confirmation
>
> def validate
> super
> validates_confirmation_of :password
> end
>
> end
>
> u = User.new
> u.username = 'foobar'
> u.email = '[email protected]'
> u.password = 'pass'
> u.password_confirmation = 'pass'
> u.save
>
>
>
> Sequel has no attr_accessible method, so I tried using
> set_allowed_columns. But I've got
>
> undefined method `validates_confirmation_of' for #<User
> @values={:username=>"foobar", :email=>"[email protected]"}>
>
> Anyone could show me an example using this method and help me out ?
>
> Thanks.
>
Sequel doesn't have a confirmation validation. Confirmation is purely a UI
level validation, not a model validation (you aren't storing two passwords
for the user), and as such does not belong in the model layer. It's logic
you should only have on the action that processes your sign up/password
change forms, not something that you should be checking every time you save
the user.
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.