why I can not accept white spaces on field for save in ruby on rails? -
i trying save form rails, simple one, , everytime try send name space (like john smith) dont error, returns succcess, not save anything, when try johnsmith works.
i checked on model , have
validates :first_name, :allow_blank => true, :format => { :with => /\a[a-za-z]+\z/, :message => "only letters allowed" } validating letters, accepting spaces, still, when try, no success.
at controller have this.
name = params[:name].to_s and later
@user.atributes = { :weight => weight, :name => name ... , on at end make @user.save
any idea how avoid problem? want accept spaces on names, without getting security problems.
thanks
result of post in console
started post "/users/custom" 192.168.1.21 @ 2013-05-21 17:51:06 -0600 processing userscontroller#custom js parameters: {"name"=>" new user", "lastname"=>" last name", "mail"=>"newuser@gmail.com", "sex"=>"0" ... n on} user load (0.1ms) select `users`.* `users` `users`.`id` = 6 limit 1 (0.1ms) begin (0.3ms) update `users` set `first_name` = ' new user', `ssn` = 0, `updated_at` = '2013-05-21 23:51:06' `users`.`id` = 6 (1.2ms) commit rendered users/custom.html.erb within layouts/application (0.1ms) completed 200 ok in 16ms (views: 11.0ms | activerecord: 1.7ms)
your regex wrong. you're accepting letters, whitespace not letter. try this: \a[a-za-z,\s]+\z
btw rubular pretty cool tool, if need test regexps.
Comments
Post a Comment