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
吗?