Mailinglist Archive: yast-devel (36 mails)

< Previous Next >
[yast-devel] user form problem and other cleanups
  • From: Duncan Mac-Vicar Prett <dmacvicar@xxxxxxx>
  • Date: Wed, 13 May 2009 18:31:40 +0200
  • Message-id: <4A0AF5EC.707@xxxxxxx>

The form now works:

form_for(:user, @user, :url => { :action => "update" }, :html => {
:method => :put } ) do |f| %>

Rails was right, the route is configured to do a put, and to get the
put, one needs to put it into the :html option.

That together with changing YaST::ServiceResource to actually use simple
class names solves the problem.
( now org.yast.foo is no longer
YaST::ServiceResource::Proxies::OrgYaSTFoo but only
YaST::ServiceResource::Proxies::Foo ) and then we will add a feature to
request the proxy with a custom class name in case you need to handle
resources named equal.

I may had broke sshkeys.

Some things that can be improved (not necessarily for the milestone):

- When one uses form_for, rails generates for fields with
name="modelname[atrrname] instead of name="attrname".

so making
@user.attrname = params[:user][:attrname] for every attribute is not needed.

as params[:user] is already a Hash with all the values, you can init the
model with the hash values:

require 'active_resource'
class Resource < ActiveResource::Base
self.site = "http://localhost:8080";
end

r = Resource.new(:a => "foo", :b => "kfk")
=> #<Resource:0x7f3fa1058560 @prefix_options={},
@attributes={"a"=>"foo", "b"=>"kfk"}>

values = {:a => "foo", :b => "kfk"}
r = Resource.new(values)
=> #<Resource:0x7f3fa1029b98 @prefix_options={},
@attributes={"a"=>"foo", "b"=>"kfk"}>

It works, so why not simply @user = User.new(params[:user]) and we save
tons of lines of code.
Now, we don't have a class User because we generate it dynamically using
YaST::ServiceResource, so @client.new(params[:user]) makes the trick.

- ssh key handling.

Right now in the web client the user ssh key is mapped to a custom
method exportSsh key. Everything is handled in the same controller using
ifs according to what form button was pressed and makes the code quite
complicated. I think we could discuss in next meeting how to make this
simpler.

--
Duncan Mac-Vicar P. - Engineering Manager, YaST
SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nuernberg)

--
To unsubscribe, e-mail: yast-devel+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-devel+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages