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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
ESPNDev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Apr-29 22:31 UTC
Re: RESTful route for member action
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 On Apr 29, 2:16 pm, TomRossi7 <t...-5bxIUPmzHicFraO2wh7vUA@public.gmane.org> wrote:> 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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, "ESPN...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <ESPN3.DL- Community...-xX8xgfAcNKEAvxtiuMwx3w@public.gmane.org> wrote:> 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 > > On Apr 29, 2:16 pm, TomRossi7 <t...-5bxIUPmzHicFraO2wh7vUA@public.gmane.org> wrote: > > > 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---