开发者

link_to problem

开发者 https://www.devze.com 2023-02-28 20:24 出处:网络
I am new to Rails and I\'m I am trying to create a basic blog application, but I\'m having trouble linking.

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' %>
开发者_StackOverflow中文版

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.


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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消