Hi i created a controller article and added the following code
def chid @message='hello world' respond_to do |format| format.html end end
I then created
chid.html.erbfile in
app/views/articles/
and wrote the following code
Hello world
When i gave the following url
../articles/chidi dunnot get any output.. am i missing something?
My log portion
Processing ArticlesController#show (for 127.开发者_开发技巧0.0.1 at 2011-01-12 21:51:01) [GET] Session ID: BAh7BzoMY3NyZl9pZCIlMTA0ZWY2ZTUzYjQxZGJkZmFlMTQwNWRjYjczNTRm%0AODAiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh%0Ac2h7AAY6CkB1c2VkewA%3D--de7737601817f52c1b72daca6061c5126f3a5022 Parameters: {"action"=>"show", "id"=>"chid", "controller"=>"articles"} Rendering template within layouts/articles Rendering articles/show Completed in 0.01000 (100 reqs/sec) | Rendering: 0.00600 (60%) | DB: 0.00000 (0%) | 200 OK [localhost/articles/chid/]
my router.rb file is as follows
ActionController::Routing::Routes.draw do |map| map.resources :articles map.connect ':controller/:action/:id' map.connect ':controller/:action/:id.:format' map.match ':controller/:action/' => 'Article#chid' end
In the config
directory there is a file named routes.rb
. This file tells Rails how to respond to certain URLs by mapping them a controller's action.
Consider the example:
match '/articles/chid' => 'Articles#chid'
This will route #{your_site_url}/articles/chid
to ArticlesController
's chid
action, which in turn would render the chid.html.erb
view located in views/articles
.
We can also tell Rails what to route /
to as well:
root :to => 'Articles#chid'
And, finally, we could also route any controller to any action using what's called Bound Parameters:
match ':controller/:action'
As a last note, definitely check out the Rails Guides on Routing.
Update:
Try using the following routes.rb
:
ActionController::Routing::Routes.draw do |map|
map.connect ':controller/:action'
end
Edit
Based on the routes.rb file you just posted, this line is the culprit. Delete it.
map.connect ':controller/:action/:id'
Note that the routes match in order from the top of the file to the bottom and once it finds a match, it's done. It won't look at the rest of your routes.
精彩评论