SitePoint Sponsor |
|
User Tag List
Results 1 to 7 of 7
Thread: routes.rb
-
Mar 3, 2006, 10:14 #1
- Join Date
- Mar 2006
- Posts
- 4
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
routes.rb
i have searched through this forum (and the web), but havent been able to find a simple explanation of routes.rb
i want to be able to simply load an index.rhtml when the browser loads http://localhost:3000/
from that page i want to be able to call some controllers by using:
Code:<%= link_to "Click here for buildings", :action => "buildings" %>
but i simply dont understand how to without invoking another controller called index, which causes other problems.
http://localhost:3000/index/buildings
which tbh is fine by me, but then i get an error message telling me it doesnt exist which is true, the building controller is not under the index controller, so i dont understand again how to instruct routes.rb to do this
any takers?
oh and hi this is my first post
-
Mar 3, 2006, 10:22 #2Code:
map.connect '', :controller => 'index', :action => 'buildings'
-
Mar 3, 2006, 12:19 #3
- Join Date
- Mar 2006
- Posts
- 4
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ok now http://localhost:3000/ gives me this: No action responded to buildings
when i go to http://localhost:3000/index/ it gives me the index.rhtml file,
but the link for buildings goes to: http://localhost:3000/
but i need it to go to http://localhost:3000/buildings
by changing the routes.rb to have this: map.connect 'buildings', :controller => 'index', :action => 'buildings'
i get No action responded to buildings, but if i change it to map.connect 'buildings/list', :controller => 'index', :action => 'buildings' it works.
however when i edit a row, and click back (using the link generated by scaffold rather that back button on browser) i get: No action responded to buildingsLast edited by Chicane; Mar 3, 2006 at 14:16.
-
Mar 3, 2006, 12:42 #4
Not sure why you are having a problem here...its not entirely clear what you are trying to do. You have some odd controller names (cfdbase??? Try and make your controller names clearer). What are your controllers and your actions? So far you've mentioned an IndexController (again not really a great name...its name should describe its purpose) and CfdbaseController, and a buildings action but which controller is this in?
Out of the box, routes should do most of the things you want them to do. The only change you should have to make is the route to connect your initial controller/action (your "index" route if you like) and routes for special URL conventions.
If you want to have a controller/action solely to act as your home/index controller, then thats fine (HomeController is a better name...it better defines its purpose than index which is just a naming convention for default web server files and in Rails' case, the default action in a controller).
Code:class HomeController < ActionController::Base def index end end # app/views/home/index.rhtml Welcome to my app etc... # routes.rb # make sure the index.html file in the public folder is removed map.connect '', :controller => 'home', :action => 'index' # http://myapp/ should now load your index action on the home controller
-
Mar 3, 2006, 14:29 #5
- Join Date
- Mar 2006
- Posts
- 4
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ok i made changes to my last post to clear up the confusion
i have now changed index to home to create a home controller.
what i wanted to do i to create a simple index page that i could link to other controllers such as buildings.
so on the index.rhtml page there would be a link to buildings which would list the buildings from the database (the dbase interaction works)
i have created a buildings controller, but when clicking on the link i get: http://localhost:3000/home/buildings
so how do i either:
1) get the link to remove /home/
or
2) put the buildings controller under /home/
-
Mar 3, 2006, 17:04 #6
Well in your original post you said you had this in your index.rhtml file:
Code:<%= link_to "Click here for buildings", :action => "buildings" %>
Code:<%= link_to "Click here for buildings", :controller => "buildings" %>
-
Mar 4, 2006, 04:10 #7
- Join Date
- Mar 2006
- Posts
- 4
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ah thanks
Bookmarks