How to use email address as parameter in PUT request for rails?

I configured the route in config.rb

resources :password 

If the parameter is not an email address, it works fine.

When the parameter is an email address, it will show me an error:

PUT "/ password / exampl e@gmail.com.json " has been launched for 127.0.0.1 on 2012-02-22 17:04:17 +0800

ActionController :: RoutingError (route mapping [PUT] "/ password / example@gmail.com.json "):

Update1

this is my password controller

  def update return_info = User.change_password(params[:id],params[:old],params[:newpw],params[:newpw2]) respond_to do |format| format.json { render :json => {:info => t(return_info)} } end end 

Thanks.

+4
source share
3 answers

if you use custom string instead of id try

 resources :password, :constraints => { :id => /.*/ } 
+10
source

Base64.urlsafe_encode64 (' robocop@mail.ua ')

 => "cm9ib2NvcEBtYWlsLnVh" 

Base64.urlsafe_decode64 ('cm9ib2NvcEBtYWlsLnVh')

 => " robocop@mail.ua " 
+5
source

Maybe I do not understand the question correctly, but perhaps the problem here is that @ not a character that you can use in URL encoding.

I suspect that the email address must be encoded before passing in the parameters, and you can do it like this:

If email = " hello@mac.com " try something like

 URI.escape(email, '@') 

It will return

 "hello%40mac.com" 
+3
source

Source: https://habr.com/ru/post/1397755/


All Articles