# RESTful route for member action

**URL:** <https://www.ruby-forum.com/t/restful-route-for-member-action/136226>\
**Category:** Rails\
**Created:** [April 29, 2008, 11:17pm UTC](https://www.ruby-forum.com/t/restful-route-for-member-action/136226 "2008-04-29T23:17:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 29, 2008, 11:17pm UTC](https://www.ruby-forum.com/t/restful-route-for-member-action/136226/1 "2008-04-29T23:17:28Z")

</div>

I have run into this scenario a couple of times and am wondering how  
other people get around it. When you create a member route it is  
intended to operate on just one of a particular model object. My  
problem is that sometimes I want to use a member route on a model  
object that may not have been created yet. This throws off the route  
generation.

Here is an example:

map.resources :user, :member =\> { :check\_email =\> :post }

So if I were to create a link with the named route:  
user\_check\_email\_path(@user) =\> /user/1/check\_email

But what if the @user is a new object? So I want to perform a member  
method on the object before it is created. In that case:  
user\_check\_email\_path(@user) =\> /user//check\_email

Shouldn’t Rails generate and recognize the route /user/check\_email for  
the check\_email method against a new unsaved @user object?

Thanks,  
Tom

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 30, 2008, 12:33am UTC](https://www.ruby-forum.com/t/restful-route-for-member-action/136226/2 "2008-04-30T00:33:08Z")

</div>

If it’s a new user why do you check their email? Shouldn’t you make  
sure @user isn’t nil before you call that action?

user\_check\_email\_path(@user) unless @user.nil?

My real recommendation though is to stick to CRUD actions. If you had  
an email\_count controller you could use the index method to grab the  
count for a user (in addition to making sure it wasn’t nil).

Also, why are you using a POST for this method? POSTs are for creation/  
deletion of data not access.

Hope this helps 🙂

ESPNDev

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 30, 2008, 1:06am UTC](https://www.ruby-forum.com/t/restful-route-for-member-action/136226/3 "2008-04-30T01:06:28Z")

</div>

This was a fictional example where an Ajax call (thus the POST) was  
being used to verify that an email address has not already been used  
in the system so you could show either a new user who is signing up  
for the first time or an existing user that is editing their  
information. In the new user scenario, their is no existing @user  
object…

On Apr 29, 6:31 pm, “removed\_email\_address@domain.invalid” \<ESPN3.DL-
