[英]Ruby on Rails passing controller variables to view
Hello I am having difficulties understanding why the parameter is not passing to the view. 您好,我很难理解为什么参数没有传递给视图。
controller 控制者
class UsersController < ApplicationController
include UsersHelper
before_filter :set_user, :set_categories
def show
@test = get_test()
end
end
helper 帮手
module UsersHelper
def get_test()
puts "hello world"
end
end
view 视图
test: <%= @test %>
What is being displayed test:
正在显示什么
test:
Can someone please give me some assistance of why hello world
is not being displayed? 有人可以给我一些为什么不显示
hello world
帮助吗? Thanks! 谢谢!
--Edit-- It seems like I am not able to even pass any variable messages to the view I added... -编辑-似乎我什至无法将任何可变消息传递给我添加的视图...
controller 控制者
@message = "How are you"
view 视图
<p><%= @message %></p>
And How are you
is not displaying. 而且
How are you
还没有显示。
In your get_test
function, you are printing a string instead of returning the string. 在
get_test
函数中,您正在打印字符串而不是返回字符串。 To return a string: 要返回一个字符串:
module UsersHelper
def get_test()
"hello world"
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.