[yast-devel] Re: [yast-commit] <rest-service> master : small fixes to restfull resource
Martin Kudlvasr write:
ref: refs/heads/master commit aa80f8228d1d0d9cd349a7b0d2f054b0138e67ed Author: Martin Kudlvasr <mkudlvasr@suse.cz> Date: Tue Sep 15 16:15:15 2009 +0200
small fixes to restfull resource --- webservice/app/controllers/resources_controller.rb | 14 ++++++-------- webservice/app/models/resource.rb | 10 ++++++++-- webservice/app/views/resources/index.html.erb | 5 ++--- webservice/app/views/resources/show.html.erb | 4 ++-- webservice/config/routes.rb | 3 ++- 5 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/webservice/app/controllers/resources_controller.rb b/webservice/app/controllers/resources_controller.rb index 087010a..ae90e04 100644 --- a/webservice/app/controllers/resources_controller.rb +++ b/webservice/app/controllers/resources_controller.rb @@ -3,23 +3,21 @@ class ResourcesController < ApplicationController
def index @resources = Resource.all + do_respond + end + + def do_respond @node = "Yast"
- logger.debug("Ahoj!") - debugger respond_to do |format| format.html format.xml { render :xml => @resources.to_xml } + format.json{ render :json=> @resources.to_json} end end
def show @resources = Resource.find(params[:id]) - @node = "Yast" - - respond_to do |format| - format.html - format.xml { render :xml => @resources.to_xml } - end + do_respond end end diff --git a/webservice/app/models/resource.rb b/webservice/app/models/resource.rb index 8cd8b1e..417ec2b 100644 --- a/webservice/app/models/resource.rb +++ b/webservice/app/models/resource.rb @@ -7,6 +7,8 @@ class Resource attr_accessor :implementations
class Implementation + attr_accessor :controller, :interface + def initialize(interface, impl_hash) @interface = interface @policy = impl_hash[:policy] @@ -15,18 +17,22 @@ class Resource end
def link_to - "/#{@controller}/#{@singular ? "show" : "index"}" + "/#{@controller}/#{action}"
^^^ This is root of actual problems. It is not true, that route is controller. It is not how is routes created in lib/resource_registration. So this two values dismatch and all plugin that have different last identifier from interface and controller name is broken. (now systemtime plugin) -- Josef Reidinger YaST team maintainer of perl-Bootloader, YaST2-Repair, webyast modules language and time -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
* Josef Reidinger <jreidinger@suse.cz> [Sep 25. 2009 16:14]:
def link_to - "/#{@controller}/#{@singular ? "show" : "index"}" + "/#{@controller}/#{action}"
^^^ This is root of actual problems. It is not true, that route is controller. It is not how is routes created in lib/resource_registration. So this two values dismatch and all plugin that have different last identifier from interface and controller name is broken. (now systemtime plugin)
Great catch, thanks ! Yes, resource routing needs fixing and we agreed to look into this together with Karel. We have to move carefully here since Rails routing is _very_ delicate. That said, the direct way (i.e. let every resource provide its own route.rb file) might not match the requirements. The requirement is to support many resource implementations while preventing them from stepping on each other toes. Example: An 'interface' resource below 'network'. This would normally translate into a Network::interface_controller (-> network/interface url). Problem: How do we support another contributor with his own implementation of network interfaces ? This whole 'base resources on dot.separated.interface.pathes' is to support i.e. org.opensuse.network.interface and com.redhat.network.interface side-by-side. The only 'standard Rails' solution I can come up with is nested modules, i.e. Org::Opensuse::Network::interface_controller (translating to app/controllers/org/opensuse/network/interface_controller.rb). Klaus --- SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg) -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
* Josef Reidinger <jreidinger@suse.cz> [Sep 25. 2009 16:14]:
def link_to - "/#{@controller}/#{@singular ? "show" : "index"}" + "/#{@controller}/#{action}"
^^^ This is root of actual problems. It is not true, that route is controller.
And after looking more closely, I wonder why the Resource model has a 'link_to' method anyways. ActionController::Base provides a 'url_for' method which was called with wrong parameters (passing a URL as controller instead of the controller path). Should be fixed now. Klaus --- SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg) -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
participants (2)
-
Josef Reidinger
-
Klaus Kaempf