ruby - Why do I get a duplicated curb request? -


i'm creating application, has authentication based on external api login/register methods. have simple controller called registrationscontroller fires request using curb.

this controller:

class registrationscontroller < applicationcontroller   def new   end    def create     if params[:user][:email].present? && params[:user][:password].present? && params[:user][:phone].present? && params[:user][:login].present?       # api request       password = params[:user][:password]       body = {         "register" => {           "password" => password,           "email" => params[:user][:email],           "phone" => params[:user][:phone],           "login" => params[:user][:login]         }       }        c = curl::easy.http_post("http://domain.com/register", body.to_json       ) |curl|         curl.headers['content-type'] = 'application/json'         curl.headers['application'] = 'appname'         curl.headers['device'] = 'www'       end        c.perform       response_body = json.parse(c.body_str)        throw response_body # line allways gives me 'login taken' error       return     else       @user = user.new(params[:user])       render action: "new", notice: 'error'     end   end end  

(i have views/registrations/new.html.slim view simple form it's not important right now.)

my routes this:

match 'users/sign_up' => 'registrations#new', :via => :get, :as => :user_register match 'users/sign_up' => 'registrations#create', :via => :post, :as => :user_create 

my application, after click "register" button on registrations#new page, triggering curb request 2 times. result, i'm getting 'login taken' error. user registered i'm not getting result first request, second one.

it's somehow caused rails , i'm 100% sure because can seen in api server logs request triggered twice. also, have same script written in php and, in there, registration works fine.

in rails dev console, request triggered 1 time it's strange.

does have idea going on here?

i found answer.

if struggles similar, caused c.perform line. remove , work fine.

i should study docs better in future.


Comments