Reputation: 2793
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.
Upvotes: 0
Views: 483
Reputation: 2793
I added this to my routes.rb:
get "static_pages/about_us"
and now it works. Thanks for your help!
Upvotes: 0
Reputation: 446
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'} %>
Upvotes: 1