Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/52.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails RubyonRails将控制器变量传递给视图_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails RubyonRails将控制器变量传递给视图

Ruby on rails RubyonRails将控制器变量传递给视图,ruby-on-rails,ruby,Ruby On Rails,Ruby,您好,我很难理解为什么参数没有传递到视图 控制器 class UsersController < ApplicationController include UsersHelper before_filter :set_user, :set_categories def show @test = get_test() end end module UsersHelper def get_test() puts "hello world" e

您好,我很难理解为什么参数没有传递到视图

控制器

class UsersController < ApplicationController
  include UsersHelper

  before_filter :set_user, :set_categories
  def show
    @test = get_test()
  end
end
module UsersHelper
   def get_test()
     puts "hello world"
   end
end
@message = "How are you"
查看

test:  <%= @test %> 
<p><%= @message %></p>
查看

test:  <%= @test %> 
<p><%= @message %></p>


并且,
如何
未显示。

获取测试
函数中,您正在打印字符串,而不是返回字符串。要返回字符串,请执行以下操作:

module UsersHelper
   def get_test()
     "hello world"
   end
end

get\u test
函数中,您正在打印字符串,而不是返回字符串。要返回字符串,请执行以下操作:

module UsersHelper
   def get_test()
     "hello world"
   end
end

get\u test
函数中,您正在打印字符串,而不是返回字符串。要返回字符串,请执行以下操作:

module UsersHelper
   def get_test()
     "hello world"
   end
end

get\u test
函数中,您正在打印字符串,而不是返回字符串。要返回字符串,请执行以下操作:

module UsersHelper
   def get_test()
     "hello world"
   end
end

谢谢,这确实解决了问题!你会不会碰巧知道如何解决我的编辑问题?你会如何返回一个变量,它只是
@hello=“hello world”
?或者它只是hello=“hello world”,并返回局部变量?对不起。我不太明白你的意思。你的意思是给变量分配一个字符串?要从函数中返回字符串,请执行以下操作:
返回“hello world”
。要让视图访问变量,通常必须将其分配给实例变量,即
@hello=“hello world”
hello
不带@将是局部变量。谢谢,这确实解决了问题!你会不会碰巧知道如何解决我的编辑问题?你会如何返回一个变量,它只是
@hello=“hello world”
?或者它只是hello=“hello world”,并返回局部变量?对不起。我不太明白你的意思。你的意思是给变量分配一个字符串?要从函数中返回字符串,请执行以下操作:
返回“hello world”
。要让视图访问变量,通常必须将其分配给实例变量,即
@hello=“hello world”
hello
不带@将是局部变量。谢谢,这确实解决了问题!你会不会碰巧知道如何解决我的编辑问题?你会如何返回一个变量,它只是
@hello=“hello world”
?或者它只是hello=“hello world”,并返回局部变量?对不起。我不太明白你的意思。你的意思是给变量分配一个字符串?要从函数中返回字符串,请执行以下操作:
返回“hello world”
。要让视图访问变量,通常必须将其分配给实例变量,即
@hello=“hello world”
hello
不带@将是局部变量。谢谢,这确实解决了问题!你会不会碰巧知道如何解决我的编辑问题?你会如何返回一个变量,它只是
@hello=“hello world”
?或者它只是hello=“hello world”,并返回局部变量?对不起。我不太明白你的意思。你的意思是给变量分配一个字符串?要从函数中返回字符串,请执行以下操作:
返回“hello world”
。要让视图访问变量,通常必须将其分配给实例变量,即
@hello=“hello world”
hello
没有@将是局部变量。您在相关操作中定义了
@message
吗?您在相关操作中定义了
@message
吗?您在相关操作中定义了
@message
吗?