Renaming RESTful actions


#1

I’ve got a RESTful controller that takes in a file upload as the main
input
into a table. I want to rename POST:resources_url to hit #upload instead
of
#create. Is there something I can specify on map.resources that allows
me to
do this? Or am I stuck generating a URL like “/resource/;upload” ?

Jason


#2

On 3/16/07, Jason R. removed_email_address@domain.invalid wrote:

I’ve got a RESTful controller that takes in a file upload as the main
input into a table. I want to rename POST:resources_url to hit #upload
instead of #create. Is there something I can specify on map.resources that
allows me to do this? Or am I stuck generating a URL like
“/resource/;upload” ?

Jason

A little more information, here’s my test (which is failing, difference
being :action => ‘create’ is generated, not ‘upload’):

assert_recognizes({:controller => 'taxes', :action => 'upload'}, 

{:path
=> ‘taxes’, :method => :post})

and current routing

map.resources :taxes, :new => {:upload => :post}

Jason


#3

On 3/16/07, François Beausoleil removed_email_address@domain.invalid wrote:

Bye !

François Beausoleil
http://blog.teksol.info/
http://piston.rubyforge.org/

I know that the old routing is still available, I’m trying to stay away
from
it as much as I can. The problem I have with REST right now is that
there is
no “accepted spec” for doing REST, if that makes any sense. When it
comes to
controllers that are a little more complex than just serving up a view
to a
model, is it ok to drop out of REST? What is the point that a site is
no-longer RESTful?

Jason


#4

2007/3/16, Jason R. removed_email_address@domain.invalid:

I know that the old routing is still available, I’m trying to stay away from
it as much as I can. The problem I have with REST right now is that there is
no “accepted spec” for doing REST, if that makes any sense. When it comes to
controllers that are a little more complex than just serving up a view to a
model, is it ok to drop out of REST? What is the point that a site is
no-longer RESTful?

You have to be pragmatic. If the REST philosophy doesn’t fit a
particular case, well, don’t bother.

Hope that helps !

François Beausoleil
http://blog.teksol.info/
http://piston.rubyforge.org/


#5

Hi,

2007/3/16, Jason R. removed_email_address@domain.invalid:

A little more information, here’s my test (which is failing, difference
being :action => ‘create’ is generated, not ‘upload’):

 assert_recognizes({:controller => 'taxes', :action => 'upload'}, {:path

=> ‘taxes’, :method => :post})

and current routing

map.resources :taxes, :new => {:upload => :post}

map.connect “/taxes/upload”, :controller => “taxes”, :action => “upload”

Everything that existed before resources still exists now that
resources are here. That’s one of the nice thing. We get to make our
cake and eat it too :slight_smile:

Bye !

François Beausoleil
http://blog.teksol.info/
http://piston.rubyforge.org/


#6

On 3/16/07, François Beausoleil removed_email_address@domain.invalid wrote:

model, is it ok to drop out of REST? What is the point that a site is
no-longer RESTful?

You have to be pragmatic. If the REST philosophy doesn’t fit a
particular case, well, don’t bother.

Hope that helps !

François Beausoleil
http://blog.teksol.info/
http://piston.rubyforge.org/

It does fit. All I’m trying to do is rename the action being used by
the
POST action (default create, I want to rename it to upload). Is this
possible?

Jason


#7

One thing I had to let go of when I started using the RESTful
methodology
was the need to have my urls all styled looking with no parameters
hanging
out looking all ugly. Sometimes getting those params inline is a matter
of
rethinking things and nesting routes but sometimes you just have to
raise up
those hands and concede to the RESTy way. I’m still bugged by things
like
http://domain.com/users/1/entries;?page=2 but I’ve come to accept them
[on
my admin side*] as accurate representations of what is important and
what is
ephemeral/peripheral information. In this case, the fact that the data
on
page two isn’t necessarily the same every time is a good indicator that
it’s
not actually a resource itself and therefore just a hanging param.
Perhaps
your desire to rename “create” to “upload” without having to change its
basic function is similar. :slight_smile:

RSL

*On my spiderable content side, I’ve heard that urls like
http://domain.com/users/1/entries;?page=2 don’t get indexed and
therefore
aren’t perhaps the best way of arranging one’s archives. YMMV


#8

Hi Jason,

Earlier on you said: Or am I stuck generating a URL like “/
resource/;upload”

Forgive me if I’m being dense, but why do you want he default POST
to call a method called update() rather than create()? It seems to
me that if you want POST /some/url to perform a specific set of
actions, why wouldn’t you just do those actions in create rather
than fight the framework?

Or, are you in fact saying that you want to have two urls to create
a resource in your :taxes resource collection: one that calls create
() and another that calls upload()?

If so, have you tried:

map.resources :taxes, :collection => {:upload => :post}

However, that most definitely does generate a resource url like /
taxes;upload so it may not be what you’re looking for.

Regards,
Trevor