I want to generate url with parameters in Laravel like this:
http://example.com/validate_email?user_id=31&confirmation_code=ihlasfsafe
I tried
URL::to('validate_email', array('user_id' => $user_id, 'confirmation_code' => $confirmation_code));
But it gives me:
http://example.com/validate_email/31/ihlasfsafe
So how can I do it correctly?
You need to use:
URL::to('validate_email').'?'.http_build_query(array('user_id' => $user_id, 'confirmation_code' => $confirmation_code));
to achieve this
Related
How to add alias to route file?
Something like this:
/rules => 'posts/1', param: id => 1
Is it possible define it in routes.rb
I want
/rules => posts/1
not
/rules/1 => posts/1
Well, let's look at the official Rails routing guide:
You can also define other defaults in a route by supplying a hash for the :defaults option. This even applies to parameters that you do not specify as dynamic segments.
So then:
get "/rules" => "posts#show", :defaults => { :id => "1" }
try this
get '/rules', to: redirect('/posts/1')
http://guides.rubyonrails.org/routing.html#redirection
im trying create url like this: www.domain.com/auth?join=social in yii.
This is my config:
'urlManager' => array(
'urlFormat' => 'path',
'rules' => array(
'<action:(auth)>' => 'site/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
'showScriptName'=>false,
),
when i calling this: www.domain.com/auth?join=social page i cant get param: join. But when i calling www.domain.com/index.php/auth?join=social i can get.
im getting param with this code: $social = Yii::app()->request->getParam('join');. Where is my error?
$social = Yii::app()->request->getParam('social');
change it with
$social = Yii::app()->request->getParam('join');
I find my error it wasnt error YII. I must be write rewrite rules in lighttpd configurations. Here explained very well. Thanks!
try
$_REQUEST['join']
in your action.
I want to send to my controller some data, and then in variables:
params[:oem_number]
params[:id]
and see there some data, but how can i send to method data? How to write this route?
Now i have such route:
match '/articles/by_oem/:id&:oem_number' => 'articles#articles_by_oem', :as => :articles_by_oem
And try to create link:
= link_to "аналоги", :articles_by_oem(:id => no.article_nr, :oem_number => no.oem)
But i get SyntaxError errors...
So how to solve my problem? Please don't send me to rails doc's...
Just how to create link, that will send this two params, and also before edit route...
first, you don't need that list of parameters on a route.
You can leave just this in your routers.rb:
/articles/by_oem/:id
And, then, what are you trying to do here?
:articles_by_oem(:id => no.article_nr, :oem_number => no.oem)
:articles_by_oem is a symbol, not a function. Use articles_by_oem_path method instead:
= link_to "аналоги", articles_by_oem_path(:id => no.article_nr, :oem_number => no.oem)
= link_to "name", articles_by_oem_path(no.article_nr, no.oem)
So I need to hit a url like mydomain.com/proxies/www.msn.com in order to fulfill some ajax requests for an API
In my route I have
get "/proxies/:url" => "proxies#get"
and I in the controller I have
url_contents = Net::HTTP.get(URI.parse(params[:url]))
which if i put /proxies/www i get
undefined method `request_uri' for #<URI::Generic:0x3f89508 URL:www>
if i put /proxies/www.msn.com
I get
No route matches [GET] "/proxies/www.msn.com"
You have two separate problems here:
You're trying to treat a URL without a scheme as an HTTP URL.
Your /proxies route won't match :urls with dots and slashes the way you're expecting it to.
For the first one, you'll have to add the schema manually:
url = 'http://' + params[:url]
content = Net::HTTP.get(URI.parse(url))
For the second one, you can use a splat-route to deal with embedded slashes and :format => false to keep Rails from trying to treat .com, for example, as a format:
get '/proxies/*url' => 'proxies#get', :format => false
If you use :url, Rails will see embedded slashes as component separators and that's probably not what you want. Without the the :format => false, Rails will try to interpret .X (for any X) as a format (just like .html, .json, ...) rather than as part of the URL.
This is applicable for rails-2
The problem is with the dot(.) I guess. Ive tried something like below and it worked.
#routes.rb
map.get_proxy 'proxies/:url', :controller => "Proxies", :action => "get", :requirements => { :url => /.*/ }
#view file
#Here dot(.) are needed to replace with its encoded string %2E
<%= link_to 'Get The Site', get_proxy_url('www.msncom') %>
#Proxies Controller
#After receiving the url the %2E need to conovert to dot(.) again.
url_contents = Net::HTTP.get(URI.parse('http://'+params[:url]))
modified as stated by #mu.
match '/proxies/:url' => 'proxies#get', :as => :proxies_get
By default, when displaying pagination numbers, the url looks like /controller/action/page:number. In my application I have defined a route:
Router::connect('/:categ', array('controller' => 'posts', 'action' => 'index'), array('categ' => '[a-zA-Z]+'));
I want the number link to be something like /:categ/:page.
I've tried with
Router::connectNamed(array('page'));
but has no effect.
Am I missing something?
You must using pagination options with url params:<?php $this->Paginator->options(array('url' => 'some params')); ?>