user603635
user603635

Reputation:

link_to problem

I am new to Rails and I'm I am trying to create a basic blog application, but I'm having trouble linking.

I have three controllers (authors, pages and static_pages). They all work fine but I'm trying to link to two pages in static_pages. They are about.html.erb and help.html.erb. I'm using a partial to create a navigation menu at the top.

I'm getting the following error:

ActionController::RoutingError in Pages#index

No route matches {:controller=>"pages", :action=>"about"}

1: <%= link_to 'Homepage', pages_path %> |
2: <%= link_to 'List of Authors', authors_path %> |
3: <%= link_to 'About', :action => 'about' %> |
4: <%= link_to 'Help', :action => 'help' %>

The code in my menu partial is:

<%= link_to 'Homepage', pages_path %> |
<%= link_to 'List of Authors', authors_path %> |
<%= link_to 'About', :action => 'about' %> |
<%= link_to 'Help', :action => 'help' %>

My static_pages controller looks like this:

class StaticPagesController < ApplicationController
  def About
  end

  def Help
  end
end

I understand that it's probably something very simple but as I say I'm new to Rails and web development in general so any advice will be appreciated.

Upvotes: 0

Views: 2004

Answers (3)

bandola
bandola

Reputation: 367

Have you checked your routes using rake routes in your terminal/console? If not this is a good way to solve problems related to route errors.

Upvotes: 0

jerom3
jerom3

Reputation: 26

Make sure that your link_to methods are trying to access the StaticPagesController, your error seems to indicate that Rails is trying to create the URL for the about action through PagesController.

Check the docs for ActionView::Helpers::UrlHelper, especially the link_to and url_for methods.

Upvotes: 0

edgerunner
edgerunner

Reputation: 14983

Trivial, make your action methods lowercase. Ruby is case sensitive with variable and method names.

class StaticPagesController < ApplicationController

  def about 
  end

  def help 
  end

end

Upvotes: 3

Related Questions