Skip to content

Instantly share code, notes, and snippets.

@royw
Created May 28, 2009 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save royw/119032 to your computer and use it in GitHub Desktop.
Save royw/119032 to your computer and use it in GitHub Desktop.
>> RestClient.post 'http://localhost:4000/commands', :command => {:process => 'Scan', :name => 'testing', :parameter => 'Movies'}
RestClient::ResourceNotFound: RestClient::ResourceNotFound
from ./bin/../lib/restclient/request.rb:187:in `process_result'
...
>> RestClient.get 'http://localhost:4000/commands/1'
=> "<command><id type='datamapper::types::serial'>1</id><parameter type='datamapper::types::text'>Movies</parameter><name>testing</name><finished_at type='datetime'>2009-05-27T19:57:41-05:00</finished_at><schedule type='datamapper::types::text'/><process>Scan</process><started_at type='datetime'>2009-05-27T19:57:41-05:00</started_at><watchdog_timeout type='integer'/><status type='datamapper::types::text'>Completed</status></command>"
And excerpts from the console log:
merb : worker (port 4000) ~ **** create ****
merb : worker (port 4000) ~ session => {}
merb : worker (port 4000) ~ params => {"format"=>nil, "command"=>{"parameter"=>"Movies", "name"=>"testing", "process"=>"Scan"}, "action"=>"create", "controller"=>"commands"}
...
merb : worker (port 4000) ~ rest_resource(nil, [#<Command id=1 parameter="Movies" name="testing" finished_at=nil schedule=nil process="Scan" started_at=nil watchdog_timeout=nil status=nil>])
merb : worker (port 4000) ~ rest_resource => /commands/1
merb : worker (port 4000) ~ Redirecting to: /commands/1 (302)
...
merb : worker (port 4000) ~ No routes match the request: /commands/1 - (Merb::ControllerExceptions::NotFound)
/Users/royw/views/gen-umm-core-merb/umm-core/gems/gems/merb-core-1.0.11/lib/merb-core/dispatch/router.rb:143:in `route_for'
Now for the create code:
def create
debug 'create'
get_parent
new_resource
attrs = get_attributes
if get_resource.update_attributes(attrs) && update_relations && @resource.save
redirect rest_resource(@parent, @resource)
else
# display error messages and reload "new" page
...
end
end
get_parent sets @parent to nil
get_attributes returns the params['command'] hash
new_resource sets @resource to model.new(get_attributes)
update_relations just returns true because @parent is nil
# parent is an Array of model instances or nil
def rest_resource(parent, *args)
Merb.logger.info "rest_resource(#{parent.inspect}, #{args.inspect})"
rsrc = nil
if parent.nil?
rsrc = resource(*args)
else
rsrc = resource(*([parent].flatten + (args || [])))
end
Merb.logger.info "rest_resource => #{rsrc}"
rsrc
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment