[Nitro] Resending: Re: Request#params

Robert Mela rob at robmela.com
Mon Oct 1 12:03:11 EDT 2007


Resending

With a fresh darcs get ( 30 minutes ago ) and this test program:

 #!/usr/bin/env ruby
 require 'ubygems'
 require 'sqlite3'
 require 'nitro_and_og'
 include Nitro
 require 'nitro/part/admin'

 # Og model
 class Book
   attr_accessor :title, String
   attr_accessor :author, String
 end

 # Controller
 class Foo
   def index
     render_text "Foo"
   end
 end

 Og.create_schema = true
 Og.use_uuid_primary_keys = true
 Og.start( :name => "library", :adapter => :sqlite, :evolve_schema => 
:full )

 app=Application.new
 app.dispatcher.root = Foo
 app.start

Saving a 'Book' produces this exception:

 ERROR: Error while handling OgAdminController#save()
 ERROR: undefined method `[]' for nil:NilClass
   
/Users/rmela/nitro2/repo.nitroproject.org/script/lib/../../raw/lib/raw/context/request.rb:304:in 
`[]'
   
/Users/rmela/nitro2/repo.nitroproject.org/script/lib/../../nitro/lib/nitro/part/admin/og/controller.rb:93:in 
`save'

Line 93 throws the exception:

    92   def save
    93     klass = name_to_class(request['object_class_name'].to_s)
    94
    95     if oid = request['oid']
    96       obj = klass[oid.to_s]
    97       obj.assign(request, :assign_relations => true, 
:force_boolean => true)
    98     else
    99       obj = klass.new
   100       obj.assign(request, :assign_relations => true)
   101     end

I modified that slightly to produce some output:

    92   def save
    93     if request.nil?
    94        puts "OGADMIN request returns 'nil'"
    95     else
    96        puts "OGADMIN request() returns a #{request.class.name}"
    97        puts "OGADMIN request.params returns #{request.params || 
'nil'}"
    98        puts "OGADMIN request['oid'] returns #{request['oid']}"
    99     end


which produced this exception:

ERROR: undefined method `[]' for nil:NilClass
/Users/rmela/nitro/repo.nitroproject.org/script/lib/../../raw/lib/raw/context/request.rb:304:in 
`[]'
/Users/rmela/nitro/repo.nitroproject.org/script/lib/../../nitro/lib/nitro/part/admin/og/controller.rb:98:in 
`save'

And this output:

OGADMIN request() returns a Raw::Context
OGADMIN request.params returns nil



Robert Mela wrote:
> You're right... but.... still....  I swear -- 'request[]' failed in 
> nitro/part/admin/og/controller.rb in OgAdminController::save
>
> I'll try a very simple test case to verify -- perhaps some code 
> included via raw/model/webfile.rb is overriding it somehow...
>
> The accessors do work as advertised in this case:
>
> #!/usr/bin/env ruby
> require 'nitro_and_og'
> include Nitro
>
>
> class Foo
>  def index
>     render_text "
>       request() returns #{request.nil? ? 'nil' : request.class.name }
>      <a href='/paramtest?a=b&c=d&foo=bar'>Parameters</a>
>     "
>  end
>  def paramtest(*args)
>    %{
>        params=#{request.params}<br/>
>        request[:foo] = #{request[:foo]}
>     }
>  end
> end
>
> app=Application.new
> app.dispatcher.root = Foo
> app.start
>
>
> Jonathan Buch wrote:
>> Hi,
>>
>>> OgAdminController#save attempts to access request data via the 
>>> 'request'
>>> method call:
>>>
>>> klass = name_to_class(*request*['object_class_name'].to_s)
>>> obj.assign(*request*, :assign_relations => true, :force_boolean => 
>>> true)
>>
>> yes, I believe that was always like that, as a shortcut to 
>> request.params.
>>
>>> A couple problems
>>>
>>>   - Major misnomer: request returns a @context object
>>
>> That I don't know about.
>>
>>>   - @request does not have a [] method for accessing incoming request
>>> variables ( nor should it...)
>>
>> Any reason why?
>>
>> * request.params['foo']
>> * request['foo']
>>
>> I use the second form all the time.
>>
>>> I've worked around it for now by calling
>>> @context.post_params['object_class_name'] .... which led up to the
>>> question in my prev. email, since @context.params would be nicer...
>>
>> I'm not sure I follow you here.  The parameters come from the "Request"
>> (requested by browser) and I'm not sure if 'context' better describes
>> where the parameters come from.  IMO they belong to the current
>> 'request cycle' and not to a 'generic context'.  But mind you, that is
>> just generally, if Nitro returns a `Context` object when you call
>> `request` then that's just kind of an alias....
>>
>>>>   31    def params
>>>>   32        return method == :post ? @post_params : @get_params
>>>>   33    end
>>
>> I'm not sure about the contents of those, but IIRC the plan (quite a 
>> while
>> back) was to do a little more:
>>
>> def params
>>   return method == :post ? @get_params.merge(@post_params) : @get_params
>> end
>>
>> (Where I assume the @get_params is an hash.)
>>
>> But that might now be obsolete when we have both .get/post_params 
>> available.
>>
>> Carry on :P
>>
>> Jo
>>
>
> _______________________________________________
> Nitro-general mailing list
> Nitro-general at rubyforge.org
> http://rubyforge.org/mailman/listinfo/nitro-general

-------------- next part --------------
A non-text attachment was scrubbed...
Name: rob.vcf
Type: text/x-vcard
Size: 116 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/nitro-general/attachments/20071001/33ba411e/attachment.vcf 


More information about the Nitro-general mailing list