views:

27

answers:

1

I'm doing a rewrite of an old Rails application and I thought I should do it in a RESTful manner, as a learning experience if nothing else.

I've reached some actions that toggles a boolean value, for example if an article is published or not.

Before I had a couple of actions: toggle_published, publish and unpublish.

They were very easy to use: i just made a link to them in the article-list.

How would you do the same thing in a RESTful manner?

Should I use the update-action, and build a mini-form to replace each link that I used before? I don't particulary like that idea.

A: 

It sounds like you have two use cases:

  • set published state
  • toggle published state

You should be able to add a member route for the toggle action for:

/articles/<id>/toggle_published - calls Article.toggle(:published)

And use Article update on :published attribute via the standard REST resource route.

map.resources :articles, :member => :toggle
Winfield