How to get the url parameter from a url - ruby-on-rails-3

I'd like to get the url parameter like below.
http://localhost:3000/g/http://google.com
So, I set config/routes.rb like below
get '/g/:url' => "urls#show"
But I can't get params[:url] in the urls#show.
How can I get the parameter?

Related

Types of url arguments when linking via <a> tag in django template

What is the difference between these linkings?:
Some Page
and
Some Page .
I've worked with the first one, and can't understand why we need to write like title='title' in the second one.
For the second you are passing 'title' as a string literal to the url parameter title, so this will work if your path looks like:
path('entry/<slug:title>/', some_view, name='entry')
for example. If the path looks like:
path('entry/<slug:slug>/', some_view, name='entry')
the name of the parameter is thus slug, not title. Regardless if you want to pass the value of the title variable, you should use:
Some Page
or in case the URL parameter is slug:
Some Page

How to make seo url for Yii $_GET method using url manager?

I'm working on a site on local server. I have made a form to search country,state and city. After getting the results I see the URL formatted as URL
I want to make this URL as URL
So here I want to know about URL manager rules so I can make it as I want.
Simply add this rule in your url-manager
"site/searchme/<country>/<state>/<city>" => "site/searchme"
Now, you need to have an action with this signature:
public function actionSearchme($country, $state, $city)
You can access $country, $state, $city from url inside this action. For example if your url be like http://localhost/yii_1/site/searchme/UnitedStates/Washington/NewYork, $country will equal "UnitedStates" and so on.

Yii transform url from param/param/param/ to param/param?param

Suppose I have a url like:
site.com/param1/value1/param2/value2/param3/value3/param4/value4
I need to convert this url when a user writes it in url line to:
site.com/param1/value1/param2/value2?param3=value3&param4=value4
P.S. - the number of parameters is variable.
How can I do it?
You need to change the UrlManager Rules according to the situation.
You need to configure the Url manager to handle the first two params as path url and let the rest

How to use a json response in Rails

I have a simple method
def country_list
#countries = User.find(:all).map(&:country).uniq
render :json => #countries
end
if the path to it is country_list_path, how can I use the response as a list for autocomplete source for example, or just displaying?
If I put anywhere country_list_path I will get the url and not the response
If you want to get the JSON data directly, you should put User.find(:all).map(&:country).uniq.to_json instead of an URL that retrieves that data.

Ember-Router: create route dynamically

I am trying to dynamically create a route to my router. I know there is serialize for doing this, but it appears to only accept a finite amount of parameters. For example, I need to be able to build a route that could be /:a or /:a/:b/:c.
My question is, is there a way to get what the original path request was?
I will need to:
get the original path
pause the router so an ajax call can be made to retrieve path info.
request from the server the path and return the module if it exists
(I have that much set up).
If path exists, create the route and move the application into that
state.
You can access the requested location via the router's location property.
You could then split the returned string and access the different parameters.
locationString = App.router.get('location.location.hash')
// something like "/1/2"
params = locationString.split(/\//)
param1 = params[1] // => "1"
param2 = params[2] // => "2"