为什么当我调用 Shoes#'visit' 时会丢失实例变量?
我确信这与鞋>中提到的复杂性有关。 手册> 规则,但我就是不明白。 如果有人愿意解释为什么在下面的代码中 @var == nil ... 我认为我可以使用访问在应用程序中的不同视图之间切换,但如果我丢失所有状态,这将不起作用。
class MyShoe < Shoes
url '/', :index
url '/somewhere', :somewhere
def index
@var = para link( "go somewhere", :click => "/somewhere" )
end
def somewhere
para "var = #{@var.inspect}"
end
end
Shoes.app
I'm sure this has to do with the intricacies mentionned in Shoes > Manual > Rules but I just don't get it. If someone would care to explain why @var == nil in the following code ...
I thought I could use visit to switch between different views in my application but that won't work if I lose all state.
class MyShoe < Shoes
url '/', :index
url '/somewhere', :somewhere
def index
@var = para link( "go somewhere", :click => "/somewhere" )
end
def somewhere
para "var = #{@var.inspect}"
end
end
Shoes.app
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
_
为什么他自己回答了这个问题,我稍后会讨论这个问题。 首先,在不同 url 之间传递数据(特别是字符串)的最简单方法是这样的:它将匹配正则表达式的子组,并将匹配的字符串作为参数传递给方法。 偶尔有用,但很快就会变得笨拙。 另一种解决方案是使用常量或类变量,如
_为什么在这里解释
:
在您的示例中,它看起来像这样:
_
why himself has answered this issue, and I'll get to that in a minute. First, the simplest way to pass data (specifically, strings) between different urls is like this:It will match the subgroups of the regex and pass the matching strings as parameters to the method. Occasionally useful, but it gets unwieldy in a hurry. The other solution is to use constants or class variables, as
_
why explains here:In your example, it would look like this: