首先,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.
嗨,在上面添加它。将
CHarris
2013-03-20 00:46:00
您是否声明了静态页面的路由? – muttonlamb 2013-03-20 00:46:53
**您的Rails版本已过时,容易受到众多安全漏洞的影响!立即升级!**。此外,六月份将不再支持Ruby 1.8.7,您应该尽快切换到Ruby 1.9或2.0。 – 2013-03-20 01:26:47