Reputation: 1442
I have a link button in an application
= link_to "Hello" , :controller => "pages" , :action => "home"
On a click of this link the generated url is "localhost:3000/pages/home". But i want, the url should be displayed like=> "localhost:3000/hello" Is there any way in rails to do this?
Upvotes: 0
Views: 369
Reputation: 16636
You could also try this
resources :pages do
collection do
get :hello
end
end
Upvotes: 0
Reputation: 5110
you can name URL as you want, and can mapped in routes.rb. In your case you can use match
Here is the example:
in your route.rb
match 'hello' => 'pages#home', :as => :hello
Now in link_to "hello", home_path
You can find more options in documentaion
Upvotes: 0
Reputation: 114248
You could set up a named route:
match 'hello' => 'pages#home', :as => :hello
In your view:
= link_to "Hello", hello_path
Upvotes: 3