Route #resource + member vs #connect

Hello,

I have a Hotel model and I mapped all routes for this class via
map.resources.

map.resources :hotels, :collection => { :search => :get, :cheapest
=> :get }

I also mapped some additional actions including a search action and a
cheapest actions that returns the list of hotels filtered with a
specific algorithm.

Now I need to implement a new feature for resolving some data
conflict.
The feature requires an action to display the conflict
(HotelController#conflict => GET) and an other action for resolving
the conflict (HotelController#resolve => PUT).

Because I have 2 different actions with different http methods but
basically related to the same feature, should I map the features using
resource :member or should I use a classic #connect and switch between
get/post checking request method within the action?

map.conflict ‘conflict’, :controller => ‘hotel’, :action => ‘conflict’
vs
map.resources :hotels, :collection => { :search => :get, :cheapest
=> :get }, :member => { :conflict => :get, :resolve_conflict
=> :put }

Is there a third option?

I see the first one is the most used but usually only because the
projects I used as examples were originally designed for Rails 1.2
without a real consideration of map.resource.

Thanks,
Simone

On May 30, 2008, at 9:27 AM, Simone C. wrote:

Is there a third option?

I see the first one is the most used but usually only because the
projects I used as examples were originally designed for Rails 1.2
without a real consideration of map.resource.

Thanks,
Simone

You can add the restriction yourself:

map.edit_account(‘account/edit/:id’, :controller =>
‘account’, :action => ‘update’,
:conditions => { :method => :post })
map.edit_account(‘account/edit/:id’, :controller =>
‘account’, :action => ‘edit’,
:conditions => { :method => :get })

Or in your case:

map.conflict ‘hotels/:id/conflict’, :controller => ‘hotel’, :action =>
‘conflict’, :conditions => { :method => :get }
map.conflict ‘hotels/:id/conflict’, :controller => ‘hotel’, :action =>
‘resolve_conflict’, :conditions => { :method => :post }

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

Thanks Rob!
Here http://github.com/bborn/communityengine/tree/master/routes.rb I
found the following statement:

resources :users, :member_path => ‘/:id’, :nested_member_path =>
‘/:user_id’, :member => {

:forgot_password => [:get, :post],
} do |user|

but it doesn’t work to me.
It only seems to accepts a :post/:get/:delete/:put or :any. Do you
know something more about this undocumented feature?

Simone

On May 30, 4:05 pm, Rob B. [email protected]

On May 30, 2008, at 4:55 PM, Simone C. wrote:

but it doesn’t work to me.
It only seems to accepts a :post/:get/:delete/:put or :any. Do you
know something more about this undocumented feature?

Simone

No, I think I found it by reading the source of the routing helpers
(or the testing support for routes). I don’t recall whether I’d tried
the [:get,:post] way and that failed or I just never needed to do that
when routing to a single action.

-Rob

Rob B. http://agileconsultingllc.com
[email protected]