link_to出错

时间:2013-12-12 02:19:01

标签: ruby-on-rails ruby ruby-on-rails-3

我收到了一个错误:

#myview
<h2><%=link_to "Controller Enable/Disable", Controller_Enable_path %></h2>

#routes.rb
 match '/Controller_Enable', to:'static_pages#Controller_Enable', via: 'get'

#controller
def Controller_Enable
        puts "Controller_Enable.................................."
    end

它显示“未初始化的常量ActionView :: CompiledTemplates :: Controller_Enable_path”,我不知道如何纠正此错误。

1 个答案:

答案 0 :(得分:1)

用小写字母写出方法名称:controller_enable。大写名称被视为常量。

应该是这样的:

#myview
<h2><%=link_to "Controller Enable/Disable", controller_enable_path %></h2>

#routes.rb
 match '/controller_enable', to:'static_pages#controller_enable', via: 'get'

#controller
def controller_enable
  puts "controller_enable.................................."
end