undefined local variable or method `hello_world' for #<#<Class:...>:...>
这是我的文件:
welcome_controller.rb
class WelcomeController < ApplicationController def hello_world "Hello,World" endend
欢迎/ index.HTML.erb
<%= hello_world %>
的routes.rb
Rails.application.routes.draw do get 'welcome/index' root 'welcome#index'end解决方法 或者做:
class WelcomeController < ApplicationController helper_method :hello_world def hello_world "Hello,World" endend
现在在视图中调用它:
<%= hello_world %>
阅读helper_method
总结Declare a controller method as a helper,to make the
hello_world
controller method available to the vIEw.
以上是内存溢出为你收集整理的ruby-on-rails – Ruby on Rails中未定义的局部变量/无方法错误全部内容,希望文章能够帮你解决ruby-on-rails – Ruby on Rails中未定义的局部变量/无方法错误所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)