使用button_to时为什么会出现错误?

时间:2013-03-12 11:17:45

标签: ruby-on-rails

给我错误的代码行是:

<%= button_to 'Search', static_pages/gallery %>

错误是:

  

未定义的局部变量或方法`static_pages'

以下是我的路线:

match "/home" => "static_pages#home"
match "/gallery" => "static_pages#gallery"

get "static_pages/home"
get "static_pages/gallery"
post "static_pages/gallery"

1 个答案:

答案 0 :(得分:1)

这是无效的语法:

<%= button_to 'Search', static_pages/gallery %>

Ruby会查找不存在的变量static_pagesgallery。它应该是一个字符串:

<%= button_to 'Search', 'static_pages/gallery' %>