views:

24

answers:

3

hi ,

i am working in Ruby on rails.. i am new to this..

i have used a line

   <%= link_to "about",about_path %>

    which throws me a error as,

    undefined local variable or method `about_path' for #<ActionView::Base:0xb5f5baa8>

i am having the page about.html under app/views/pages/

please give some suggestions of why i am getting like this .

+1  A: 

Is in your routes.rb something like map.resources :about ?

If you don't know why it should be there or what is that, read about RESTful Routing on guides.

retro
This would only make sense if you have a model called "about". He just wants to route a static page ...
auralbee
+2  A: 

I guess your about page is "static". Check this..

routes.rb

# rails 2.3.x
map.about "/pages", :controller => 'pages', :action => 'about'

Controllers/pages_controller.rb

class PagesController < ApplicationController
  def about # not needed, only for "tidiness"

  end
end

... and your erb file have to be here: Views\pages\about.html.erb

baijiu
+3  A: 

Your code is looking for what is called a named route. You need to define these in config/routes.rb. In addition you will need some controller and action to handle them. See this post describing a very simple way to handle static pages by way of illustration.

To get the about_path named route, then you would add this to routes.rb

map.about "/pages/about", :controller => "pages", :action => "show", :id => "about"

Then add your about page contents to a file called app/views/pages/about.html.erb

Finally:

$ rake routes

tells you all of the named routes defined for your application and what they do

bjg
@John Topley. Thanks for fixing those typos
bjg