0

First of all, pretty new to Rails. I've been following a tutorial on using the 'link_to' command - basically, I have some links with text 'About Us', 'FAQ', 'Contact Us', and I want them to link to their respective pages.

Following the tutorial, the code in my contact_us.html.erb file goes like this:

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

My controller is called static_pages_controller.rb and I have an about_us method in that file, with no code in it:

def about_us
end

My controller code is:

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

I get the error:

NameError in Static_pages#contact_us

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

Any ideas what's wrong? I think it might be because the tutorial is for ruby 1.8.6 and Rails 2.0.2, and I have Ruby 1.8.7 and Rails 3.2.7. I heard Rails is notorious for not being backwards compatible. Should I change my code? To what? Thanks for any help.

C.

Community
  • 1
  • 1
CHarris
  • 2,693
  • 8
  • 45
  • 71
  • Hi, added it in above. Changed < ApplicationController to BaseController, but got the error 'uninitialized constant BaseController' – CHarris Mar 20 '13 at 00:46
  • Do you have route declared for the static pages? – muttonlamb Mar 20 '13 at 00:46
  • **Your version of Rails is out-of-date and vulnerable to numerous security vulnerabilities! Upgrade immediately!**. Further, Ruby 1.8.7 will no longer be supported in June, you should switch to Ruby 1.9 or 2.0 as soon as possible. – Andrew Marshall Mar 20 '13 at 01:26

2 Answers2

1

Hi I think your problem it's you are using instead of normal single quotes (') or doubled quotes (") when passing the parameters values in the link_to method

Change this:

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

to this:

<%= link_to "About Us", {:controller => 'static_pages', :action => 'about_us'} %>
FedeX
  • 426
  • 2
  • 8
0

I added this to my routes.rb:

get "static_pages/about_us"

and now it works. Thanks for your help!

CHarris
  • 2,693
  • 8
  • 45
  • 71