Restful routes

If I created a route like this map.about '/about', :controller => 'pages', :action => 'about

And then added this to a different page <%= link_to "About", about_url %>

And decided to change my route to map.resources :about

the link to no longer works.

What am I doing wrong?

And how about your Page Controller, did you change it to About Controller?

In your first implementation you’ve used Pages Controller to create your About page. If you didn’t change it to and About Controller you can to do something loke that:

map.resources :pages, :member => { :about => :get }

's

An "about us" page is not a candidate for a rest resource. You had it fine before.

If you turned your pages controller into a rest resource and moved the "about" page into the resulting cms, then you might create a helper method "about_url" that generates the newly correct url.

If you wanted users to be able to create many "abouts", edit and destroy them, then you would create an "abouts_controller". The index action would give a list of abouts (abouts_url would link to it). If you want to view an individual "about" then about_url(@about). To edit it, edit_about_url(about). To update it, the form_for(@about) will take care of the put method. Likewise, link_to "delete about", about_url(about), :method => :delete will remove it. To create a new one, new_about_url will get you there.

The correct answer is:

map.resources :pages, :collection => {:home => :get, :about => :get, :contact => :get }

and then the link_to becomes:

<%= link_to 'About', about_pages_path%>

Ron Green wrote:

The correct answer is:

map.resources :pages, :collection => {:home => :get, :about => :get, :contact => :get }

and then the link_to becomes:

<%= link_to 'About', about_pages_path%>

This is a bit of a perversion of map.resources. You probably want to just consider this :controller/:action (which the default routes already provide).

[Please don't top-post.]

Best,

This is not a real app. so stuff your perversion and top posting. I got this from RailsCasts

Ron Green wrote:

This is not a real app. so stuff your perversion and top posting.

Be polite if you want help. And if it's not a real app, then why waste your time on it? Presumably to learn good practice, right?

I got this from RailsCasts #35 Custom REST Actions - RailsCasts

Yes, it will work. My point was that it's conceptually wrong for what you're doing -- you don't want to make every static page a custom REST action.

Best,

I understand. My apologies for my rudeness.