Routing generated paths in Ruby on Rails
Posted
by True Soft
on Stack Overflow
See other posts from Stack Overflow
or by True Soft
Published on 2010-02-01T19:34:37Z
Indexed on
2010/05/13
5:14 UTC
Read the original article
Hit count: 566
ruby-on-rails
|routing
I'm a beginner in ruby-on-rails and I spent my last hour trying to do the following thing:
I have a ruby-on-rails application - the blog with posts and categories.
I want to have another URL for the posts (I would like to have http://localhost:3000/news
instead of http://localhost:3000/posts
) First I tried to replace the controller and classes from Posts
to News
, but I gave up(because of the annoyng singular-plural thing). Then in my I replaced map.resources :posts
(case 1) to
map.resources :news, :controller => "posts" #case 2
or
map.resources :posts, :as => 'news' #case 3
in routes.rb
as I saw on some websites. It doesn't work either.
How can I do this?
EDIT:
the output of rake routes
is (only first lines):
for case 1 and 3:
posts GET /posts {:action=>"index", :controller=>"posts"}
formatted_posts GET /posts.:format {:action=>"index", :controller=>"posts"}
POST /posts {:action=>"create", :controller=>"posts"}
POST /posts.:format {:action=>"create", :controller=>"posts"}
new_post GET /posts/new {:action=>"new", :controller=>"posts"}
formatted_new_post GET /posts/new.:format {:action=>"new", :controller=>"posts"}
edit_post GET /posts/:id/edit {:action=>"edit", :controller=>"posts"}
formatted_edit_post GET /posts/:id/edit.:format {:action=>"edit", :controller=>"posts"}
post GET /posts/:id {:action=>"show", :controller=>"posts"}
formatted_post GET /posts/:id.:format {:action=>"show", :controller=>"posts"}
PUT /posts/:id {:action=>"update", :controller=>"posts"}
PUT /posts/:id.:format {:action=>"update", :controller=>"posts"}
DELETE /posts/:id {:action=>"destroy", :controller=>"posts"}
DELETE /posts/:id.:format {:action=>"destroy", :controller=>"posts"}
the output for case 2:
news_index GET /news {:action=>"index", :controller=>"posts"}
formatted_news_index GET /news.:format {:action=>"index", :controller=>"posts"}
POST /news {:action=>"create", :controller=>"posts"}
POST /news.:format {:action=>"create", :controller=>"posts"}
new_news GET /news/new {:action=>"new", :controller=>"posts"}
formatted_new_news GET /news/new.:format {:action=>"new", :controller=>"posts"}
edit_news GET /news/:id/edit {:action=>"edit", :controller=>"posts"}
formatted_edit_news GET /news/:id/edit.:format {:action=>"edit", :controller=>"posts"}
news GET /news/:id {:action=>"show", :controller=>"posts"}
formatted_news GET /news/:id.:format {:action=>"show", :controller=>"posts"}
PUT /news/:id {:action=>"update", :controller=>"posts"}
PUT /news/:id.:format {:action=>"update", :controller=>"posts"}
DELETE /news/:id {:action=>"destroy", :controller=>"posts"}
DELETE /news/:id.:format {:action=>"destroy", :controller=>"posts"}
I have errors in case 2, because in my sourcecode I don't have edit_news
, I have for example <%= link_to 'Edit', edit_post_path(post) %>
© Stack Overflow or respective owner