REST own action

I can sent my own action to a users_controller stating in routes.rb
map.resources :users, :member => { :network => get }

I defined in my users_controller the network action…
so I can have an url like
http://localhost:3000/users/168.xml;network

now I would like to have another action network_plus which is a little
bit different fron the network…

sure, I can state another action… but is there any possibility to
use only one action and perform differently according to a parameter…

how can I pass parameters to the network action ?
http://localhost:3000/users/168.xml;network&plus=true” … is it
correctly RESTFUL?..

thanks for your lights

kad

On 5/10/07, Kad K. [email protected] wrote:

sure, I can state another action… but is there any possibility to
use only one action and perform differently according to a parameter…

how can I pass parameters to the network action ?
http://localhost:3000/users/168.xml;network&plus=true” … is it
correctly RESTFUL?..

thanks for your lights

Parameters need to start with a ?, and are separated by the &.

…/168.xml;network?plus=true


Rick O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com

Rick O. wrote:

On 5/10/07, Kad K. [email protected] wrote:

sure, I can state another action… but is there any possibility to
use only one action and perform differently according to a parameter…

how can I pass parameters to the network action ?
http://localhost:3000/users/168.xml;network&plus=true” … is it
correctly RESTFUL?..

thanks for your lights

Parameters need to start with a ?, and are separated by the &.

…/168.xml;network?plus=true


Rick O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com

thanks sorry for the typing mistake… so it’s so simple as url…
thanks

On May 10, 8:54 am, Kad K. [email protected]
wrote:

sure, I can state another action… but is there any possibility to
use only one action and perform differently according to a parameter…

how can I pass parameters to the network action ?
http://localhost:3000/users/168.xml;network&plus=true” … is it
correctly RESTFUL?..

It’s ok to use the parameters to further “refine” your action, but
just make sure that your custom action shouldn’t really be a standard
action of another resource. It could very well be that although your
“network” action seems to be needed on a user resource, perhaps you’re
really stumbling upon a discovery of a new resource entirely.

What does the network action try to do? And if you had to stick to
the seven RESTful actions, what action would “network” be and for what
resource?

Those are the kinds of questions I ask myself whenever I feel like
adding a custom action, and about half the time, I’m able to just
declare a new resource and remove the custom action.

Jeff
softiesonrails.com

On Thu, May 10, 2007 at 02:11:15PM -0000, Jeff wrote :

Those are the kinds of questions I ask myself whenever I feel like
adding a custom action, and about half the time, I’m able to just
declare a new resource and remove the custom action.

+1.

Actually, everything (authorizations, logins, search, …) can be fit
into
the 7 REST actions. It’s just sometimes hard to figure out what sort of
resource do you need.


,========================.
| Pierre-Alexandre M. |
| email : [email protected] |
`========================’

Is this URL correct?

…/168.xml;network

or should it actually be

…/168;network.xml

this always confuses me. Should the format extension always appear at
very end of the URL, just before the query string. Before the
semicolon before the custom action?

On 5/10/07, Robert W. [email protected] wrote:

very end of the URL, just before the query string. Before the
semicolon before the custom action?

I think this was one of the reasons we changed it to / in edge rails.
When we actually got to building real restful apps with custom
actions, singleton resources, etc, it was clear using the semicolon
wasn’t working out (plus, safari won’t send http basic auth with it).
It should be /168/network.xml, which is a lot easier to grasp,
provides a transparent migration to a singleton ‘network’ resource
should it be necessary, and doesn’t mess with caching.


Rick O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com

Oh thank goodness. Great move! I’m looking forward to the release of
this. I like that idea so much better.

It also removes the confusion between

http://localhost:3000/resource/new

and

http://localhost:3000/resource/:id;edit

If you think about it they are both used to GET the form and not
modify the resource. Yet “new” has a slash and “edit” has a
semicolon.

So I would love to write this instead:

http://localhost:3000/resource/:id/edit

And this will also make custom actions (when they are necessary) feel
more like first class citizens in the URL.

Rick O. wrote:

On 5/10/07, Robert W. [email protected] wrote:

very end of the URL, just before the query string. Before the
semicolon before the custom action?

I think this was one of the reasons we changed it to / in edge rails.
When we actually got to building real restful apps with custom
actions, singleton resources, etc, it was clear using the semicolon
wasn’t working out (plus, safari won’t send http basic auth with it).
It should be /168/network.xml, which is a lot easier to grasp,
provides a transparent migration to a singleton ‘network’ resource
should it be necessary, and doesn’t mess with caching.


Rick O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com

could be, but…
no route found to match “/users/168/network.xml” with {:method=>:get}
no route found to match “/users/168;network.xml” with {:method=>:get}

only http://localhost:3000/users/168.xml;network is correctly
executed…

also how shoudl I write the URL in my rxml ?, I wrote
:dataURL =>
http://localhost:3000/users/#{friend.id}.xml;network?from=#{@user.id}&level=#{@level}

which generates…
dataURL=“http://localhost:3000/users/126.xml;network?from=168&level=1
this URL accepted but u can see the “amp;level” parameter ???
params => {“format”=>“xml”, “amp;level”=>“1”, “from”=>“168”, “amp”=>"",
“level”=>“1”, “action”=>“network”, “id”=>“126”, “controller”=>“users”}

thanks for your help
kad

On Thu, May 10, 2007 at 08:15:31AM -0700, Robert W. wrote :

Before the semicolon before the custom action?

Be careful, semicolon will be deprecated in Rails2.0
http://dev.rubyonrails.org/changeset/6485


,========================.
| Pierre-Alexandre M. |
| email : [email protected] |
`========================’

Jeff C. wrote:

On May 10, 8:54 am, Kad K. [email protected]
wrote:

sure, I can state another action… but is there any possibility to
use only one action and perform differently according to a parameter…

how can I pass parameters to the network action ?
http://localhost:3000/users/168.xml;network&plus=true” … is it
correctly RESTFUL?..

It’s ok to use the parameters to further “refine” your action, but
just make sure that your custom action shouldn’t really be a standard
action of another resource. It could very well be that although your
“network” action seems to be needed on a user resource, perhaps you’re
really stumbling upon a discovery of a new resource entirely.

What does the network action try to do? And if you had to stick to
the seven RESTful actions, what action would “network” be and for what
resource?

Those are the kinds of questions I ask myself whenever I feel like
adding a custom action, and about half the time, I’m able to just
declare a new resource and remove the custom action.

Jeff
softiesonrails.com

the network action return an xml files where the ‘friends’ of a user are
described (friends_who_know_me and friends_i_know) one node
for each friend and one node for each friend.residence… it’s a
complete description of a user’s network, which is built from user’s
relationships
so it’s a GET the network of a User…

I agree that it’s a resource but not in the DB… it’s point I did not
catch very well in RESTFul approach, it seems that all resources ARE
ActiveResources… true or false ?

kad

On Thu, May 10, 2007 at 06:07:01PM +0200, Kad K. wrote :

the network action return an xml files where the ‘friends’ of a user are
described (friends_who_know_me and friends_i_know) one node
for each friend and one node for each friend.residence… it’s a
complete description of a user’s network, which is built from user’s
relationships
so it’s a GET the network of a User…

Why don’t you create a resource ‘network’ which returns your formatted
xml? You could also add routes like ‘network/fred/paris’
(‘network/:person/:location/’) to GET from
this resource only the friends of fred located in Paris.

I agree that it’s a resource but not in the DB… it’s point I did not
catch very well in RESTFul approach, it seems that all resources ARE
ActiveResources… true or false ?

Resources are only a way to see some data on your network. It’s like
models: it could be directly linked to real data in your database or
not. For example, I use an ‘auth’ resource for my login/logout actions
which
maps to cookies.
login POST a cookie, is_logged_in? is a GET on a cookie etc.

My $0.02,


,========================.
| Pierre-Alexandre M. |
| email : [email protected] |
`========================’

could be, but…
no route found to match “/users/168/network.xml” with {:method=>:get}
no route found to match “/users/168;network.xml” with {:method=>:get}

only http://localhost:3000/users/168.xml;network is correctly
executed…

The change was made in edge rails for Rails 2.0.

also how shoudl I write the URL in my rxml ?, I wrote
:dataURL =>
http://localhost:3000/users/#{friend.id}.xml;network?from=#{@user.id}&level=#{@level}

network_user_path(:id => friend, :from => @user, :level => @level)
formatted_network_user_path(:id => friend, :from => @user, :level =>
@level, :format => :xml)


Rick O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs