Routes how to hide them on the url bar rails 3
My route file has the following in it for the root. what i want is when i click on say about it doesn't show me http://127.0.0.1:3000/home/abou
t what i would like is either http://127.0.0.1:3000/about
or just the URL http://127.0.0.1:3000/
like root dose. I'm running rails 3 if you can post a snip it of a route file that will do this or give me a url to see it at that would be great.
# You can have the root of your site routed wi开发者_如何转开发th "root"
# just remember to delete public/index.html.
root :to => "home#index"
# See how all your routes lay out with "rake routes"
well, if you have a controller home
with an action about
and want to call about directly, you can do something in your routes like match "/about" => "home#about" :as => :about
if you want to call the route, for example by using a link_to
you can say it like this:
<%= link_to "Home", about_url %>
you can do rake:routes
to see all the generated routes, you'll see one mapped to about
with controller => home
and action => about
Then, when you call http://localhost/about
it will actually call the home controller's about action
you can read more material about routing here
Check out http://edgeguides.rubyonrails.org/routing.html for more details.
- You should put the root route at the end of the file.
- You need to delete the public/index.html file for the root route to take effect.
- Make sure you have a home controller
- Make sure you have a view called index in the views/home/ folder
Then http://127.0.0.1:3000/
will display your index action
If you want your root to go to the about action, also change the route file to root :to => "home#about". Of course make sure you have an about view.
精彩评论