dziorkowsky
dziorkowsky

Reputation: 51

How to add alias in routes.rb

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

Upvotes: 2

Views: 296

Answers (2)

Matt Brictson
Matt Brictson

Reputation: 11092

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" }

Upvotes: 2

Max Williams
Max Williams

Reputation: 32943

try this

get '/rules', to: redirect('/posts/1')

http://guides.rubyonrails.org/routing.html#redirection

Upvotes: 1

Related Questions