On Thu, Jun 19, 2008 at 1:12 PM, _why <[EMAIL PROTECTED]> wrote:
> On Thu, Jun 19, 2008 at 12:39:01PM -0400, John Wells wrote:
>> I've read the NKS cover to cover, but think I might be misunderstanding 
>> scope.
>>
>> For example, in the lastest (git pull; rake) version of shoes, this code:
>> #############################
>> class MyApp < Shoes
>>   url "/", :index
>>   url "/next", :next
>>
>>   def index
>>     @x = edit_line
>>     para(link("next", :click=>"/next"))
>>   end
>>
>>   def next
>>     begin
>>       alert (@x.text)
>>     rescue Exception=>e
>>       puts e
>>     end
>>   end
>> end
>>
>> Shoes::app
>> #############################
>>
>> Outputs "undefined method `text' for nil:NilClass" on the console. So
>> @x is nil. However, if I read NKS correctly, especially page 36, @x
>> should still exist and the text should be accessible.
>
> Since @x is created at the "/" URL, you can't access it from the
> "/next" URL.  It's actually not a matter of scoping, it's that there
> are two objects here.
>
>  "/" => MyApp.new.index
>  "/next" => MyApp.new.next
>
> Perhaps it would be better to have one object.  I'll have to think
> about this a bit further.


Interesting. So what would be the recommended way of sharing data
between urls? Global variables or something along those lines?

Thanks,
John

Reply via email to