ruby on rails - Undefined split method while using request.url -


i trying current url of page , parameters go it. when manually put url in, undefined split method error not occur. have tried following:

request.url

request.original_url

request.fullpath

adding in

id = request.original_url 

and adding function

def original_url   base_url + original_fullpath end 

what work me below, cannot have same url , parameters every time method won't work later on.

   #parse current url     #what below in comment     #id = request.original_url     url =   "http://127.0.0.1:3000/reviews/new?id=2"     uri    = uri.parse(url)     params = cgi.parse(uri.query)     id     = params['id'].first 

any or tips on if i'm missing appreciated.

had same issue. absence of query parameters in url causing it.

url = "http://127.0.0.1:3000/reviews/new" # no query params uri = uri.parse(url) query = uri.query # nil params = cgi.parse(query) # undefined split exception 

this solves it:

uri = uri.parse(url) if uri.query   params = cgi.parse(uri.query)   id = params['id'].first end 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -