2013-03-20 90 views
0

首先,Rails很新颖。我一直在关注使用'link_to'命令的教程 - 基本上,我与'关于我们','常见问题','与我们联系'的文本有一些链接,我希望它们链接到各自的页面。Rails 3.2.7和link_to

在介绍之后,我contact_us.html.erb文件中的代码是这样的:

<%= link_to "About Us", {:controller => ‘static_pages’, :action => ’about_us’} %> 

我的控制器被称为static_pages_controller.rb,我有该文件中的about_us方法,其中不带代码:

def about_us 
end 

我的控制器代码是:

class StaticPagesController < ApplicationController 
    def about_us 
    end 

    def faq 
    end 

    def contact_us 
    end 

    def t_and_c 
    end 

    def t_and_c_competition 
    end 

    def show 
    end 
end 

我得到的错误:

NameError in Static_pages#contact_us

undefined local variable or method `‘static_pages'......etc

任何想法有什么不对?我想这可能是因为这个教程是针对Ruby 1.8.6和Rails 2.0.2的,我有Ruby 1.8.7和Rails 3.2.7。我听说Rails因不向后兼容而臭名昭着。我应该更改我的代码吗?什么?谢谢你的帮助。

C.

+0

嗨,在上面添加它。将 CHarris 2013-03-20 00:46:00

+0

您是否声明了静态页面的路由? – muttonlamb 2013-03-20 00:46:53

+0

**您的Rails版本已过时,容易受到众多安全漏洞的影响!立即升级!**。此外,六月份将不再支持Ruby 1.8.7,您应该尽快切换到Ruby 1.9或2.0。 – 2013-03-20 01:26:47

回答

1

您好我认为你的问题是,你正在使用,而不是普通的单引号(')或传递参数的值当的link_to方法

更改此一倍引号(“):

<%= link_to "About Us", {:controller => ‘static_pages’, :action => ’about_us’} %> 

这样:

<%= link_to "About Us", {:controller => 'static_pages', :action => 'about_us'} %> 
+0

同意,错误的报价。 – m4tm4t 2013-03-20 00:49:24

0

我的广告DED这对我的routes.rb:

GET “static_pages/about_us”

,现在它的工作原理。谢谢你的帮助!